-- Companies table for EGRUL data tracking
CREATE TABLE IF NOT EXISTS companies (
    id SERIAL PRIMARY KEY,
    inn VARCHAR(12) UNIQUE NOT NULL,
    name VARCHAR(500),
    ogrn VARCHAR(15),
    egrul_data JSONB,
    pdf_path VARCHAR(500),
    last_check TIMESTAMP,
    created_at TIMESTAMP DEFAULT NOW(),
    updated_at TIMESTAMP DEFAULT NOW()
);

-- Index for finding stale records
CREATE INDEX IF NOT EXISTS idx_companies_last_check ON companies(last_check);
CREATE INDEX IF NOT EXISTS idx_companies_inn ON companies(inn);

-- Example data (можно удалить)
INSERT INTO companies (inn) VALUES
    ('027415832097'),  -- БАКИЕВ РУСЛАН ШАМИЛЬЕВИЧ
    ('7707083893'),    -- СБЕРБАНК
    ('7736050003')     -- ГАЗПРОМ
ON CONFLICT (inn) DO NOTHING;
