import { ApiProperty } from '@nestjs/swagger';
import { SHIPMENT_TYPE } from 'src/utils/constants';
import {
  IsArray,
  IsBoolean,
  IsMongoId,
  IsNotEmpty,
  IsOptional,
  IsString,
  IsEnum,
} from 'class-validator';

export class CreateShipmentDto {
  @IsString()
  @IsOptional()
  @ApiProperty({ required: false, type: String, description: 'Company name' })
  company_name: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({ required: true, type: String, description: 'Phone number' })
  phone_number: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({ required: true, type: String, description: 'Country code' })
  country_phone_code: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({ required: true, type: String, description: 'First name' })
  first_name: string;

  @IsNotEmpty()
  @IsEnum(SHIPMENT_TYPE, {
    message: 'shipment_type must be GLOBAL or DUBAILLC',
  })
  shipment_type: SHIPMENT_TYPE;

  @IsOptional()
  @IsString()
  @ApiProperty({ required: false, type: String, description: 'Last name' })
  last_name: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Is this a new company',
  })
  is_new_company: string;

  @IsOptional()
  @IsString()
  @ApiProperty({ required: false, type: String, description: 'Email' })
  email: string;

  // @IsString()
  // @IsNotEmpty()
  // name_en: string;

  // @IsOptional()
  // @IsString()
  // name_ar: string;

  // @IsString()
  // @IsNotEmpty()
  // commodity_en: string;

  // @IsOptional()
  // @IsString()
  // commodity_ar: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Pickup place name in english',
  })
  pickup_from_en: string; //////pickup place in english/////////

  @IsOptional()
  @IsString()
  @ApiProperty({
    required: false,
    type: String,
    description: 'Pickup place name in arabic',
  })
  pickup_from_ar: string; //////pickup place in arabic///////

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Delivery place name in english',
  })
  delivered_to_en: string; //////delivery place in arabic///////

  @IsOptional()
  @IsString()
  @ApiProperty({
    required: false,
    type: String,
    description: 'Delivery place name in arabic',
  })
  delivered_to_ar: string; //////delivery place in arabic///////

  @IsString()
  @IsMongoId()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Shipment mode id provided from all shipment modes',
  })
  shipment_mode: string;

  @IsString()
  @IsOptional()
  @ApiProperty({ required: false, type: String, description: 'Bill of lading' })
  bill_of_lading: string;

  @IsArray()
  @IsOptional()
  @ApiProperty({
    required: false,
    description: 'Container number',
  })
  container_number: any;

  @IsOptional()
  @IsString()
  @ApiProperty({ required: false, type: String, description: 'Container type' })
  container: string;

  @IsOptional()
  @IsString()
  @ApiProperty({ required: false, type: String, description: 'Vessel name' })
  vessel_name: string;

  @IsOptional()
  @IsString()
  @ApiProperty({ required: false, type: String, description: 'Voyage' })
  voyage: string;

  @IsOptional()
  @IsString()
  @ApiProperty({
    required: false,
    type: String,
    description: `Agent's person name`,
  })
  person_name_agent: string;

  @IsOptional()
  @IsString()
  @ApiProperty({ required: false, type: String, description: 'Agent name' })
  agent: string;

  @IsOptional()
  @IsString()
  @ApiProperty({ required: false, type: String, description: 'Shipping line' })
  shipping_line: string;

  @IsOptional()
  @IsString()
  @ApiProperty({
    required: false,
    type: String,
    description: 'Shipment status',
  })
  shipment_status: string;

  @IsOptional()
  @ApiProperty({
    required: false,
    type: Array<EmployeeDto>,
    description: 'All employees',
  })
  employees: any | Array<EmployeeDto>;

  @IsOptional()
  @IsString()
  @ApiProperty({
    required: false,
    type: String,
    description: 'Estimated time of arrival',
  })
  eta: string;

  @IsOptional()
  @IsString()
  @ApiProperty({
    required: false,
    type: Array<CommodityDto>,
    description: 'Estimated time of departure',
  })
  etd: string;

  @IsNotEmpty()
  @ApiProperty({
    required: false,
    type: String,
    description: 'All Commodities',
  })
  commodity: any | Array<CommodityDto>;

  @IsOptional()
  @ApiProperty({
    required: false,
    type: Array<String>,
    description: 'Removed employees from company',
  })
  removed_employees: any | Array<string>;
}

export class EmployeeDto {
  @IsString()
  @IsNotEmpty()
  @ApiProperty({ required: true, type: String, description: 'Phone number' })
  phone_number: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({ required: true, type: String, description: 'Country code' })
  country_phone_code: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({ required: true, type: String, description: 'First name' })
  first_name: string;

  @IsOptional()
  @IsString()
  @ApiProperty({ required: false, type: String, description: 'Last name' })
  last_name: string;

  @IsBoolean()
  @IsNotEmpty()
  @ApiProperty({ required: true, type: Boolean, description: 'View shipment' })
  view_shipment: boolean;

  @IsString()
  @IsOptional()
  @ApiProperty({ required: false, type: String, description: 'email' })
  email: string;

  @IsBoolean()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: Boolean,
    description: 'Show this employee invoice',
  })
  show_invoice: boolean;

  @IsOptional()
  @IsString()
  @ApiProperty({
    required: false,
    type: String,
    description: 'Employee id if its previous employee',
  })
  employee_id: string;
}

export class CommodityDto {
  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Commodity name in english',
  })
  name_en: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Commodity name in arabic',
  })
  name_ar: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({
    required: true,
    type: String,
    description: 'Commodity volume',
  })
  volume: string;

  @IsString()
  @IsNotEmpty()
  @ApiProperty({ required: true, type: String, description: 'Weight' })
  weight: string;

  @IsBoolean()
  @IsOptional()
  @ApiProperty({
    required: false,
    type: String,
    description: `If it's new or not`,
  })
  new: boolean;

  @IsString()
  @IsOptional()
  @ApiProperty({ required: false, type: String, description: 'Quantity' })
  quantity: string;
}
