import TeamModel from '@/Model/team' ; import StadiumModel from '@/Model/stadium' ; import ChannelModel from '@/Model/channel' ; import * as moment from 'moment' ; import { Moment } from 'moment' ; class MatchModel { private id : number ; private homeTeam : TeamModel | string ; private awayTeam : TeamModel | string ; private homeResult : number | null ; private awayResult : number | null ; private homePenalty : number | null ; private awayPenalty : number | null ; private date : Moment ; private stadium : StadiumModel ; private channels : ChannelModel [ ] | null ; private type : string ; private groupname : string ; private rawHometeam : string | null ; private rawAwayteam : string | null ; public constructor ( id , homeTeam , awayTeam , homeResult , awayResult , date , stadium , channels , type , rawHometeam = null , rawAwayteam = null , groupname = null ) { this . id = id ; this . homeTeam = homeTeam ; this . awayTeam = awayTeam ; this . homeResult = homeResult ; this . awayResult = awayResult ; this . date = date ; this . stadium = stadium ; this . channels = channels ; this . type = type ; this . rawHometeam = rawHometeam ; this . rawAwayteam = rawAwayteam ; this . groupname = groupname ; } public getId ( ) { return this . id ; } public getHomeTeam ( ) { return this . homeTeam ; } public getAwayTeam ( ) { return this . awayTeam ; } public getHomeResult ( ) { return this . homeResult ; } public setHomeResult ( result ) { this . homeResult = result ; } public getHomePenalty ( ) { return this . homePenalty ; } public setHomePenalty ( result ) { this . homePenalty = result ; } public getAwayPenalty ( ) { return this . awayPenalty ; } public setAwayPenalty ( result ) { this . awayPenalty = result ; } public getAwayResult ( ) { return this . awayResult ; } public setAwayResult ( result ) { this . awayResult = result ; } public getDate ( ) { return this . date ; } public getStadium ( ) { return this . stadium ; } public getChannels ( ) { return this . channels ; } public getType ( ) { return this . type ; } public isFinish ( ) { return this . getHomeResult ( ) !== null && this . getAwayResult ( ) !== null ; } public isStarted ( ) { const now = moment ( ) ; return now . isAfter ( this . getDate ( ) ) ; } public getWinner ( ) { if ( this . getHomePenalty ( ) && this . getAwayPenalty ( ) ) { if ( this . getHomePenalty ( ) > this . getAwayPenalty ( ) ) { return this . getHomeTeam ( ) ; } return this . getAwayTeam ( ) ; } if ( this . getHomeResult ( ) > this . getAwayResult ( ) ) { return this . getHomeTeam ( ) ; } return this . getAwayTeam ( ) ; } public getLoser ( ) { if ( this . getHomePenalty ( ) && this . getAwayPenalty ( ) ) { if ( this . getHomePenalty ( ) > this . getAwayPenalty ( ) ) { return this . getAwayTeam ( ) ; } return this . getHomeTeam ( ) ; } if ( this . getHomeResult ( ) < this . getAwayResult ( ) ) { return this . getHomeTeam ( ) ; } return this . getAwayTeam ( ) ; } public setHomeTeam ( team ) { this . homeTeam = team ; } public setAwayTeam ( team ) { this . awayTeam = team ; } public getRawHometeam ( ) { return this . rawHometeam ; } public getRawAwayteam ( ) { return this . rawAwayteam ; } public getGroupname ( ) { return this . groupname ; } } export default MatchModel ;