-- Create tables for WorkCom inspections
CREATE TABLE IF NOT EXISTS workcom_inspection_types (
    id SERIAL PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    form_id INTEGER DEFAULT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE IF NOT EXISTS workcom_inspections (
    id SERIAL PRIMARY KEY,
    date DATE NOT NULL,
    location VARCHAR(255) DEFAULT NULL,
    short_description VARCHAR(255) DEFAULT NULL,
    inspector_id INTEGER DEFAULT NULL,
    inspection_type_id INTEGER DEFAULT NULL,
    workplace_id INTEGER DEFAULT NULL,
    inspection_request_id INTEGER DEFAULT NULL,
    form_data jsonb DEFAULT NULL,
    tenant_id INTEGER DEFAULT NULL,
    branch_id INTEGER DEFAULT NULL,
    isDeleted BOOLEAN NOT NULL DEFAULT FALSE,
    updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE INDEX workcom_inspections_workplace_idx ON workcom_inspections(workplace_id);
CREATE INDEX workcom_inspections_request_idx ON workcom_inspections(inspection_request_id);
