"""Shared models for JustCall autodialer jobs."""

from __future__ import annotations

from typing import Dict, List, Optional

from pydantic import BaseModel, Field


class SourceInfo(BaseModel):
    spreadsheet_id: str
    sheet_name: str
    range_a1: str
    row_count: Optional[int] = None


class JustCallMapping(BaseModel):
    phone: str
    first_name: Optional[str] = None
    last_name: Optional[str] = None
    email: Optional[str] = None
    company: Optional[str] = None
    custom_fields: Dict[str, str] = Field(default_factory=dict)


class JustCallWriteback(BaseModel):
    enabled: bool = True
    status_column: str = "JustCall Status"
    campaign_column: str = "JustCall Campaign"
    contact_id_column: str = "JustCall Contact ID"
    pushed_at_column: str = "JustCall Pushed At"
    error_column: str = "JustCall Error"
    message_enabled: bool = False
    message_sent_column: str = "JustCall Message Sent"
    message_error_column: str = "JustCall Message Error"


class JustCallConfig(BaseModel):
    profile_id: str
    campaign_id: str
    source: SourceInfo
    starting_row: int
    mapping: JustCallMapping
    writeback: JustCallWriteback = Field(default_factory=JustCallWriteback)
    tags: List[str] = Field(default_factory=list)
    upload_id: Optional[str] = None
    row_count: Optional[int] = None
    send_message: Optional[str] = None
    message_body: Optional[str] = None
    whatsapp_template_id: Optional[str] = None
    justcall_number: Optional[str] = None
    notify_email: Optional[str] = None
    spreadsheet_url: Optional[str] = None
