import { Injectable } from '@nestjs/common';
import { UserEntity } from '../../modules/user/entities/user.entity';

@Injectable()
export class MobileOnboardingStateService {
  isReadyToComplete(user: UserEntity, onboardingData: any) {
    if (
      user?.onboardingStatus !== 'in_progress' ||
      user?.role !== 'seeker' ||
      (user.selectedRoleCategory !== 'white_collar' &&
        user.selectedRoleCategory !== 'blue_collar')
    ) {
      return false;
    }

    const profile = onboardingData?.profile;
    if (!profile?.profession_id) {
      return false;
    }

    const hasBasicStepOneData = Boolean(
      user.fullName && user.phone && profile?.date_of_birth && profile?.gender,
    );

    if (user.selectedRoleCategory === 'white_collar') {
      const skills = profile?.skills_ids;
      return Boolean(
        hasBasicStepOneData &&
        onboardingData?.address?.communication_address &&
        user.email &&
        profile?.education_id &&
        profile?.experiences_id &&
        profile?.professional_title &&
        Array.isArray(skills) &&
        skills.length > 0,
      );
    }

    return Boolean(
      hasBasicStepOneData &&
      profile?.preferred_work_city_id &&
      profile?.preferred_work_locality_area_id &&
      Array.isArray(onboardingData?.roleExperiences) &&
      onboardingData.roleExperiences.length > 0,
    );
  }
}
