import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
import { SeasonPeriodEntity } from '../../domain/entities/season-period.entity';
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
import { BaseStatusModel } from 'src/core/modules/data/model/base-status.model';
import { EnumDays } from '../../constants';
import { SeasonTypeModel } from 'src/modules/season-related/season-type/data/models/season-type.model';
import { ItemRateModel } from 'src/modules/item-related/item-rate/data/models/item-rate.model';

@Entity(TABLE_NAME.SEASON_PERIOD)
export class SeasonPeriodModel
  extends BaseStatusModel<SeasonPeriodEntity>
  implements SeasonPeriodEntity
{
  @Column('date', { name: 'start_date', nullable: true })
  start_date: Date;

  @Column('date', { name: 'end_date', nullable: true })
  end_date: Date;

  @Column('simple-array', { name: 'days', nullable: true })
  days: EnumDays[];

  @Column('varchar', { name: 'holiday_name', nullable: true })
  holiday_name: string;

  @Column('int', { name: 'priority', default: 3 })
  priority: number;

  @Column('varchar', { name: 'season_type_id', nullable: true })
  season_type_id: string;
  @ManyToOne(() => SeasonTypeModel, (model) => model.season_periods, {
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  @JoinColumn({ name: 'season_type_id' })
  season_type: SeasonTypeModel;

  // relasi ke item rates
  @OneToMany(() => ItemRateModel, (model) => model.season_period, {
    cascade: true,
    onDelete: 'CASCADE',
    onUpdate: 'CASCADE',
  })
  item_rates: ItemRateModel[];
}
