import { BaseStatusDto } from 'src/core/modules/infrastructure/dto/base-status.dto';
import { TransactionUserType, TransactionPaymentType } from '../../constants';
import { ApiProperty } from '@nestjs/swagger';
import {
  IsArray,
  IsEmail,
  IsNumber,
  IsObject,
  IsString,
  ValidateIf,
} from 'class-validator';
import { SeasonPeriodEntity } from 'src/modules/season-related/season-period/domain/entities/season-period.entity';
import { TransactionItemEntity } from '../../domain/entities/transaction-item.entity';

export class TransactionDto extends BaseStatusDto {
  @ApiProperty({
    type: Object,
    required: false,
    example: {
      id: 'uuid',
      season_type: {
        id: 'uuid',
        name: 'high season',
      },
    },
  })
  @IsObject()
  @ValidateIf((body) => body.season_period)
  season_period: SeasonPeriodEntity;

  @ApiProperty({
    type: String,
    required: true,
    example: TransactionUserType.GROUP,
  })
  @IsString()
  customer_type: TransactionUserType;

  @ApiProperty({
    type: String,
    required: true,
    example: 'Andika',
  })
  @IsString()
  customer_name: string;

  @ApiProperty({
    type: String,
    required: false,
    example: '0823...',
  })
  @ValidateIf((body) => body.customer_phone)
  customer_phone: string;

  @ApiProperty({ required: false, example: 'andika@mail.com' })
  @IsEmail({ ignore_max_length: true })
  @ValidateIf((body) => body.customer_email)
  customer_email: string;

  @ApiProperty({
    type: String,
    required: false,
    example: 'Influencer',
  })
  @ValidateIf((body) => body.customer_description)
  customer_description: string;

  @ApiProperty({
    type: Number,
    required: true,
    example: 1,
  })
  @IsNumber()
  no_of_group: number;

  @ApiProperty({
    type: Date,
    required: true,
    example: '2024-01-01',
  })
  booking_date: Date;

  @ApiProperty({
    type: String,
    required: false,
  })
  @ValidateIf((body) => body.discount_code)
  discount_code: string;

  @ApiProperty({
    type: Number,
    required: false,
  })
  @ValidateIf((body) => body.discount_percentage)
  discount_percentage: number;

  @ApiProperty({
    type: Number,
    required: false,
  })
  @ValidateIf((body) => body.discount_value)
  discount_value: number;

  @ApiProperty({
    type: String,
    required: false,
    example: TransactionPaymentType.MIDTRANS,
  })
  payment_type: TransactionPaymentType;

  @ApiProperty({
    type: Number,
    required: true,
    example: 7000000,
  })
  @IsNumber()
  payment_sub_total: number;

  @ApiProperty({
    type: Number,
    required: false,
    example: 3500000,
  })
  @IsNumber()
  @ValidateIf((body) => body.payment_discount_total)
  payment_discount_total: number;

  @ApiProperty({
    type: Number,
    required: true,
    example: 3500000,
  })
  @IsNumber()
  payment_total: number;

  @ApiProperty({
    type: [Object],
    required: true,
    example: [
      {
        item: {
          id: '68aa12f7-2cce-422b-9bae-185eb1343b94',
          created_at: '1718876384378',
          status: 'active',
          name: 'tes',
          item_type: 'bundling',
          hpp: '100000',
          base_price: '100000',
          limit_type: 'no limit',
          limit_value: 0,
          item_category: {
            id: 'ab15981a-a656-4efc-856c-b2abfbe30979',
            name: 'Kategori Bundling 2',
          },
          bundling_items: [
            {
              id: 'bd5a7a38-df25-4203-a1cd-bf94867946b2',
              name: 'Wahana 21 panjangggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg',
            },
          ],
          tenant: null,
        },
        qty: 40,
        total_price: 4000000,
      },
    ],
  })
  @IsArray()
  items: TransactionItemEntity[];
}
