Files
iptv/scripts/models/country.ts

59 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-03-29 11:39:46 +03:00
import { Collection, Dictionary } from '@freearhey/core'
import { Region, Language } from '.'
type CountryData = {
2023-09-15 18:40:35 +03:00
code: string
name: string
2025-03-29 11:39:46 +03:00
lang: string
2023-09-15 18:40:35 +03:00
flag: string
}
export class Country {
code: string
name: string
flag: string
2025-03-29 11:39:46 +03:00
languageCode: string
language?: Language
subdivisions?: Collection
regions?: Collection
constructor(data: CountryData) {
this.code = data.code
this.name = data.name
this.flag = data.flag
this.languageCode = data.lang
}
withSubdivisions(subdivisionsGroupedByCountryCode: Dictionary): this {
this.subdivisions = subdivisionsGroupedByCountryCode.get(this.code) || new Collection()
return this
}
withRegions(regions: Collection): this {
this.regions = regions.filter(
(region: Region) => region.code !== 'INT' && region.includesCountryCode(this.code)
)
return this
}
withLanguage(languagesGroupedByCode: Dictionary): this {
this.language = languagesGroupedByCode.get(this.languageCode)
return this
}
getLanguage(): Language | undefined {
return this.language
}
getRegions(): Collection {
return this.regions || new Collection()
}
2023-09-15 18:40:35 +03:00
2025-03-29 11:39:46 +03:00
getSubdivisions(): Collection {
return this.subdivisions || new Collection()
2023-09-15 18:40:35 +03:00
}
}