-- 005_core_task.sql — core.task (EVA-задачи)

CREATE TABLE core.task (
    id bigserial PRIMARY KEY,
    eva_id text UNIQUE NOT NULL,
    code text,
    name text,
    project_id bigint REFERENCES core.project,
    responsible_id bigint REFERENCES core.employee,
    cache_status_type text NOT NULL CHECK (cache_status_type IN ('OPEN','IN_PROGRESS','IN_REVIEW','CLOSED')),
    eva_status_id text,
    eva_status_name text,
    cmf_created_at timestamptz,
    cmf_modified_at timestamptz,
    status_in_progress_start timestamptz,
    deadline timestamptz,
    last_synced timestamptz
);

CREATE INDEX idx_task_responsible ON core.task (responsible_id);
CREATE INDEX idx_task_status ON core.task (cache_status_type);
CREATE INDEX idx_task_project ON core.task (project_id);
CREATE INDEX idx_task_modified ON core.task (cmf_modified_at DESC);
