Files
iptv/scripts/models/subdivision.ts

43 lines
1014 B
TypeScript
Raw Normal View History

2025-04-16 20:54:55 +03:00
import { SubdivisionData, SubdivisionSerializedData } from '../types/subdivision'
2025-03-29 11:39:46 +03:00
import { Dictionary } from '@freearhey/core'
import { Country } from '.'
2023-09-15 18:40:35 +03:00
export class Subdivision {
code: string
name: string
2025-03-29 11:39:46 +03:00
countryCode: string
country?: Country
2025-04-16 20:54:55 +03:00
constructor(data?: SubdivisionData) {
if (!data) return
2025-03-29 11:39:46 +03:00
this.code = data.code
this.name = data.name
this.countryCode = data.country
}
2025-04-16 20:54:55 +03:00
withCountry(countriesKeyByCode: Dictionary): this {
this.country = countriesKeyByCode.get(this.countryCode)
return this
}
serialize(): SubdivisionSerializedData {
return {
code: this.code,
name: this.name,
countryCode: this.code,
country: this.country ? this.country.serialize() : undefined
}
}
deserialize(data: SubdivisionSerializedData): this {
this.code = data.code
this.name = data.name
this.countryCode = data.countryCode
this.country = data.country ? new Country().deserialize(data.country) : undefined
2023-09-15 18:40:35 +03:00
2025-03-29 11:39:46 +03:00
return this
2023-09-15 18:40:35 +03:00
}
}