import {
  BelongsTo,
  Column,
  DataType,
  ForeignKey,
  Model,
  Table,
} from 'sequelize-typescript';
import {
  ManualPriceStatus,
  NonSourceFeedName,
  SourceFeedName,
} from '../enum/feed.enum';
import { IPriceFeedManualPriceHistoryAttr } from '../interfaces/price-feed-manual-price-history-attr.interface';
import FeedModel from './price-feed.entity';

@Table({
  tableName: 'price_FeedManualPriceHistory',
  timestamps: false,
})
export default class FeedManualPriceHistoryModel
  extends Model
  implements IPriceFeedManualPriceHistoryAttr
{
  @Column({
    primaryKey: true,
    allowNull: false,
    type: DataType.STRING(30),
  })
  FeedManualPriceHistoryId: string;

  @ForeignKey(() => FeedModel)
  @Column({
    allowNull: false,
    type: DataType.STRING(50),
  })
  FeedName: SourceFeedName | NonSourceFeedName;

  @Column({
    allowNull: false,
    type: DataType.DECIMAL(10, 2),
  })
  BuyPrice: number;

  @Column({
    allowNull: false,
    type: DataType.DECIMAL(10, 2),
  })
  SellPrice: number;

  @Column({
    allowNull: false,
    type: DataType.STRING(20),
  })
  Status: ManualPriceStatus;

  @Column({
    allowNull: false,
    type: DataType.DATE,
  })
  ActivationDateTime: Date;

  @Column({
    allowNull: true,
    type: DataType.STRING(30),
  })
  ActivatedById: string;

  @Column({
    allowNull: true,
    type: DataType.DATE,
  })
  DeactivationDateTime: Date;

  @Column({
    allowNull: true,
    type: DataType.STRING(30),
  })
  DeactivatedById: string;

  @BelongsTo(() => FeedModel)
  Feed: FeedModel;
}
