CREATE TABLE autocode_fine (
    id uuid PRIMARY KEY NOT NULL,
    ruling_number character varying(64) NOT NULL,
    autocode_id BIGINT,
    autocode_payment_confirmation_id BIGINT,
    violation_time timestamp with time zone,
    ruling_date date NOT NULL,
    discount_date date,
    article_koap TEXT NOT NULL,
    violation_place TEXT NOT NULL,
    sum_to_pay numeric(9,2) NOT NULL,
    odps_code character varying(16),
    odps_name TEXT,
    violation_document_number character varying(36) NOT NULL,
    violation_document_type character varying(13) NOT NULL,
    has_photo boolean NOT NULL,
    fine_information_received_at timestamp with time zone NOT NULL,
    payment_confirmation_received_at timestamp with time zone,
    car_id uuid NOT NULL,
    order_id uuid,
    user_id uuid,
    charge_email_sent_at timestamp with time zone,
    charge_sms_sent_at timestamp with time zone,
    charged_at timestamp with time zone,
    charge_passed_at timestamp with time zone,
    charge_push_sent_at timestamp with time zone,
    needs_charge boolean NOT NULL,
    sum_to_pay_without_discount numeric(9,2) NOT NULL,
    violation_latitude double precision,
    violation_longitude double precision,
    is_after_ride_start_during_order boolean NOT NULL,
    is_camera_fixation boolean NOT NULL,
    skipped integer,
    session_id character varying(36),
    source_type TEXT NOT NULL,
    meta_info TEXT,
    "serial_id" BIGSERIAL NOT NULL,
    added_at_timestamp BIGINT NOT NULL,

    UNIQUE (ruling_number, source_type),
    UNIQUE ("serial_id"),

    FOREIGN KEY (car_id) REFERENCES "car"(id)
);
