-- CreateTable
CREATE TABLE `users` (
    `id` VARCHAR(191) NOT NULL,
    `name` VARCHAR(255) NOT NULL,
    `email` VARCHAR(255) NULL,
    `gender` VARCHAR(100) NULL,
    `cpf` VARCHAR(11) NULL,
    `type` INTEGER NOT NULL DEFAULT 2,
    `email_verified_at` DATETIME(3) NULL,
    `status` BOOLEAN NOT NULL DEFAULT true,
    `password` VARCHAR(191) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_at` DATETIME(3) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `addresses` (
    `id` VARCHAR(191) NOT NULL,
    `city` VARCHAR(100) NOT NULL DEFAULT 'Cametá',
    `street` VARCHAR(100) NULL,
    `number` VARCHAR(10) NOT NULL,
    `district` VARCHAR(100) NULL,
    `zipcode` VARCHAR(10) NOT NULL DEFAULT '68400000',
    `region` VARCHAR(100) NOT NULL DEFAULT 'Norte',
    `uf` VARCHAR(2) NOT NULL DEFAULT 'PA',
    `zone` VARCHAR(100) NOT NULL DEFAULT 'Urbana',
    `county` VARCHAR(191) NOT NULL DEFAULT 'Cametá',
    `latitude` VARCHAR(30) NULL,
    `longitude` VARCHAR(30) NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_at` DATETIME(3) NULL,
    `user_id` VARCHAR(191) NOT NULL,

    UNIQUE INDEX `addresses_user_id_key`(`user_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `forms_responses` (
    `id` VARCHAR(191) NOT NULL,
    `age_group` VARCHAR(191) NOT NULL,
    `reason_not_cpf` VARCHAR(191) NULL,
    `school_level` VARCHAR(191) NOT NULL,
    `religion` VARCHAR(191) NOT NULL,
    `comorbidity` BOOLEAN NOT NULL,
    `diabetes` BOOLEAN NOT NULL,
    `heart_problem` BOOLEAN NOT NULL,
    `kidney_disease` BOOLEAN NOT NULL,
    `thyroid` BOOLEAN NOT NULL,
    `obesity` BOOLEAN NOT NULL,
    `other_comorbidity` VARCHAR(191) NOT NULL,
    `affected_covid_19` BOOLEAN NOT NULL,
    `diagnostic_confirmation` BOOLEAN NOT NULL,
    `time_interval` VARCHAR(191) NOT NULL,
    `diagnostic_method` VARCHAR(191) NOT NULL,
    `treatment_place` VARCHAR(191) NOT NULL,
    `hospital_treatment` VARCHAR(191) NOT NULL,
    `covid_sequelae` VARCHAR(191) NOT NULL,
    `vaccinated` BOOLEAN NOT NULL DEFAULT false,
    `vaccine_doses` VARCHAR(191) NOT NULL,
    `reason_not_to_take` VARCHAR(191) NOT NULL,
    `lost_family_member` BOOLEAN NOT NULL DEFAULT false,
    `affected_covid_after_vaccinated` BOOLEAN NOT NULL DEFAULT false,
    `rehabilitation_sequelae` BOOLEAN NOT NULL DEFAULT false,
    `treatment_rehabilitation_sequelae` VARCHAR(191) NOT NULL,
    `opinion_prevention_measures` VARCHAR(191) NOT NULL,
    `covid_information` VARCHAR(191) NOT NULL,
    `maintained_family_income` BOOLEAN NOT NULL DEFAULT false,
    `received_social_assistance` BOOLEAN NOT NULL DEFAULT false,
    `recovered_family_income` BOOLEAN NOT NULL DEFAULT false,
    `family_in_debt` BOOLEAN NOT NULL DEFAULT false,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_at` DATETIME(3) NULL,
    `user_common_id` VARCHAR(191) NOT NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `forms_responses_on_users` (
    `user_census_taker_id` VARCHAR(191) NOT NULL,
    `form_response_id` VARCHAR(191) NOT NULL,
    `status` BOOLEAN NOT NULL DEFAULT true,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_at` DATETIME(3) NULL,

    PRIMARY KEY (`user_census_taker_id`, `form_response_id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `exported_files` (
    `id` VARCHAR(191) NOT NULL,
    `user_id` VARCHAR(191) NOT NULL,
    `filename` VARCHAR(191) NOT NULL,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,
    `deleted_at` DATETIME(3) NULL,

    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `addresses` ADD CONSTRAINT `addresses_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `forms_responses` ADD CONSTRAINT `forms_responses_user_common_id_fkey` FOREIGN KEY (`user_common_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `forms_responses_on_users` ADD CONSTRAINT `forms_responses_on_users_user_census_taker_id_fkey` FOREIGN KEY (`user_census_taker_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `forms_responses_on_users` ADD CONSTRAINT `forms_responses_on_users_form_response_id_fkey` FOREIGN KEY (`form_response_id`) REFERENCES `forms_responses`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `exported_files` ADD CONSTRAINT `exported_files_user_id_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
