import {
  Column,
  DataType,
  HasMany,
  Table,
  Model,
  ForeignKey,
  BelongsTo,
} from 'sequelize-typescript';
import FeedHistoryModel from './price-feed-history.entity';
import FeedCutOffHistoryModel from './price-feed-cut-off-history.entity';
import { ISourceFeedAttr } from '../interfaces/price-source-feed-attr.interface';
import FeedModel from './price-feed.entity';
import { SourceFeedName } from '../enum/feed.enum';

@Table({
  tableName: 'price_SourceFeed',
  timestamps: false,
})
export default class SourceFeedModel extends Model implements ISourceFeedAttr {
  @ForeignKey(() => FeedModel)
  @Column({
    primaryKey: true,
    allowNull: false,
    type: DataType.STRING(50),
  })
  FeedName: SourceFeedName;

  @Column({
    allowNull: false,
    type: DataType.STRING(20),
  })
  Status: string;

  @Column({
    allowNull: false,
    type: DataType.CHAR(1),
  })
  IsSourceFeedAvailableYN: string;

  @Column({
    allowNull: false,
    type: DataType.CHAR(1),
  })
  IsFeedCutOffYN: string;

  @Column({
    allowNull: true,
    type: DataType.DECIMAL(4, 2),
  })
  AutomaticCutOffVariance: number;

  @Column({
    allowNull: true,
    type: DataType.INTEGER,
  })
  AutomaticCutOffMinutes: number;

  @Column({
    allowNull: true,
    type: DataType.STRING(30),
  })
  CurrentCutOffHistoryId: string;

  @BelongsTo(() => FeedModel)
  Feed: FeedModel;

  @HasMany(() => FeedHistoryModel)
  FeedHistories: FeedHistoryModel[];

  @HasMany(() => FeedCutOffHistoryModel)
  FeedCutOffHistories: FeedCutOffHistoryModel[];
}
