-- Add manual verification fields for candidates

-- Add nursing-related boolean fields to candidate_education table
ALTER TABLE app.candidate_education
    ADD COLUMN nursing_related_degree BOOLEAN,
    ADD COLUMN accredited_university BOOLEAN,
    ADD COLUMN accredited_study_program BOOLEAN;

-- Add corresponding AI-extracted fields to maintain the pattern
ALTER TABLE app.candidate_education
    ADD COLUMN ai_nursing_related_degree BOOLEAN,
    ADD COLUMN ai_accredited_university BOOLEAN,
    ADD COLUMN ai_accredited_study_program BOOLEAN;

-- Update the existing constraint to include the new AI fields
ALTER TABLE app.candidate_education
DROP CONSTRAINT ai_data_requires_document;

ALTER TABLE app.candidate_education
ADD CONSTRAINT ai_data_requires_document CHECK (
    (source_document_id IS NOT NULL) OR
    (ai_institution IS NULL AND
     ai_country IS NULL AND
     ai_program IS NULL AND
     ai_duration_years IS NULL AND
     ai_completion_date IS NULL AND
     ai_nursing_related_degree IS NULL AND
     ai_accredited_university IS NULL AND
     ai_accredited_study_program IS NULL AND
     ai_extracted_by IS NULL AND
     ai_extraction_date IS NULL)
);

-- Add document verification fields to candidate_document table
ALTER TABLE app.candidate_document
    ADD COLUMN document_verified_at TIMESTAMPTZ,
    ADD COLUMN document_verified_by UUID REFERENCES app.user(user_id);

-- Update candidate table qualification status fields
ALTER TABLE app.candidate
    ADD COLUMN qualification_status_home_country app.nurse_recognition,
    ADD COLUMN qualification_status_germany app.nurse_recognition,
    DROP COLUMN recognition_status;

-- Add transcript summary fields to candidate table
ALTER TABLE app.candidate
    ADD COLUMN transcripts_total_hours INTEGER,
    ADD COLUMN transcripts_total_theory_hours INTEGER,
    ADD COLUMN transcripts_total_practice_hours INTEGER,
    ADD COLUMN transcripts_theory_and_practice BOOLEAN,
    ADD COLUMN transcripts_structured_training BOOLEAN,
    ADD COLUMN license_mandatory BOOLEAN;

-- Drop language fields from candidate_language table
ALTER TABLE app.candidate_language
    DROP COLUMN language,
    DROP COLUMN ai_language;

-- Drop duplicate accreditation field from candidate_education table
ALTER TABLE app.candidate_education
    DROP COLUMN is_accredited,
    DROP COLUMN ai_is_accredited;