-- Tables: Serviços / Prontuários
-- Gerado automaticamente em 2026-04-21T23:16:34.956Z
-- Total: 8

CREATE TABLE public.commitment_services (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    commitment_id uuid NOT NULL,
    service_id uuid NOT NULL,
    quantity integer DEFAULT 1 NOT NULL,
    unit_price numeric(10,2) NOT NULL,
    discount_pct numeric(5,2) DEFAULT 0,
    discount_flat numeric(10,2) DEFAULT 0,
    final_price numeric(10,2) NOT NULL,
    created_at timestamp with time zone DEFAULT now(),
    CONSTRAINT commitment_services_disc_flat_chk CHECK ((discount_flat >= (0)::numeric)),
    CONSTRAINT commitment_services_disc_pct_chk CHECK (((discount_pct >= (0)::numeric) AND (discount_pct <= (100)::numeric))),
    CONSTRAINT commitment_services_final_price_chk CHECK ((final_price >= (0)::numeric)),
    CONSTRAINT commitment_services_quantity_chk CHECK ((quantity > 0))
);

CREATE TABLE public.commitment_time_logs (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    tenant_id uuid NOT NULL,
    commitment_id uuid NOT NULL,
    calendar_event_id uuid,
    source public.commitment_log_source DEFAULT 'manual'::public.commitment_log_source NOT NULL,
    started_at timestamp with time zone NOT NULL,
    ended_at timestamp with time zone NOT NULL,
    minutes integer NOT NULL,
    created_by uuid,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);

CREATE TABLE public.determined_commitment_fields (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    tenant_id uuid NOT NULL,
    commitment_id uuid NOT NULL,
    key text NOT NULL,
    label text NOT NULL,
    field_type public.determined_field_type DEFAULT 'text'::public.determined_field_type NOT NULL,
    required boolean DEFAULT false NOT NULL,
    sort_order integer DEFAULT 0 NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);

CREATE TABLE public.determined_commitments (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    tenant_id uuid NOT NULL,
    created_by uuid,
    is_native boolean DEFAULT false NOT NULL,
    native_key text,
    is_locked boolean DEFAULT false NOT NULL,
    active boolean DEFAULT true NOT NULL,
    name text NOT NULL,
    description text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL,
    bg_color text,
    text_color text
);

CREATE TABLE public.insurance_plan_services (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    insurance_plan_id uuid NOT NULL,
    name text NOT NULL,
    value numeric(10,2) NOT NULL,
    active boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now()
);

CREATE TABLE public.insurance_plans (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    owner_id uuid NOT NULL,
    tenant_id uuid NOT NULL,
    name text NOT NULL,
    notes text,
    default_value numeric(10,2),
    active boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now()
);

CREATE TABLE public.medicos (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    owner_id uuid NOT NULL,
    tenant_id uuid NOT NULL,
    nome text NOT NULL,
    crm text,
    especialidade text,
    telefone_profissional text,
    telefone_pessoal text,
    email text,
    clinica text,
    cidade text,
    estado text DEFAULT 'SP'::text,
    observacoes text,
    ativo boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now()
);

CREATE TABLE public.services (
    id uuid DEFAULT gen_random_uuid() NOT NULL,
    owner_id uuid NOT NULL,
    tenant_id uuid NOT NULL,
    name text NOT NULL,
    description text,
    price numeric(10,2) NOT NULL,
    duration_min integer,
    active boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone DEFAULT now(),
    updated_at timestamp with time zone DEFAULT now()
);
