import { ITomeiPriceHistoryAttr } from '../interfaces/price-tomei-price-history-attr.interface';
import {
  BelongsTo,
  Column,
  DataType,
  ForeignKey,
  Model,
  Table,
} from 'sequelize-typescript';
import FeedHistoryModel from './price-feed-history.entity';
import FeedModel from './price-feed.entity';
import { NonSourceFeedName } from '../enum/feed.enum';

@Table({
  tableName: 'price_TomeiPriceHistory',
  timestamps: false,
})
export default class TomeiPriceHistoryModel
  extends Model
  implements ITomeiPriceHistoryAttr
{
  @Column({
    primaryKey: true,
    type: DataType.STRING(30),
  })
  TomeiPriceHistoryId: string;

  @ForeignKey(() => FeedHistoryModel)
  @Column({
    allowNull: false,
    type: DataType.STRING(30),
  })
  FeedHistoryId: string;

  @ForeignKey(() => FeedModel)
  @Column({
    allowNull: false,
    type: DataType.STRING(50),
  })
  FeedName: NonSourceFeedName;

  @Column({
    allowNull: false,
    type: DataType.CHAR(3),
  })
  Currency: string;

  @Column({
    allowNull: false,
    type: DataType.DATE,
  })
  DateTime: Date;

  @Column({
    allowNull: false,
    type: DataType.DECIMAL(10, 2),
  })
  BuyLabourCharges: number;

  @Column({
    allowNull: false,
    type: DataType.DECIMAL(10, 2),
  })
  SellLabourCharges: number;

  @Column({
    allowNull: true,
    type: DataType.DECIMAL(5, 2),
  })
  AdjustBuyPercentage: number;

  @Column({
    allowNull: true,
    type: DataType.DECIMAL(5, 2),
  })
  AdjustSellPercentage: number;

  @Column({
    allowNull: false,
    type: DataType.DECIMAL(10, 2),
  })
  TomeiBuyPrice: number;

  @Column({
    allowNull: false,
    type: DataType.DECIMAL(10, 2),
  })
  TomeiSellPrice: number;

  @Column({
    allowNull: true,
    type: DataType.STRING(30),
  })
  AdjustedById: string;

  @Column({
    allowNull: true,
    type: DataType.DATE,
  })
  AdjustedDateTime: Date;

  @Column({
    allowNull: true,
    type: DataType.CHAR(1),
  })
  IsManualPriceActivatedYN: string;

  @BelongsTo(() => FeedHistoryModel)
  FeedHistory: FeedHistoryModel;

  @BelongsTo(() => FeedModel)
  Feed: FeedModel;
}
