"""
PRD-HWONB-015 — Application Setup (association / leadSource / salesRep) schema.

Supersedes PRD-HWONB-002's "invisible bootstrap" (§1: "not a screen the
merchant sees") and PRD-HWONB-014's bootstrap-then-PATCH flow for
`association` alone. All three of GP's Create Application merchant-facing
values are now collected together here, before Business Information (Step 1
of 12), and sent on the real `POST /applications` call itself.

`association` keeps PRD-HWONB-014's exact validation (Developer Guide p.85:
6 digits, must not start with 7). `leadSource` has no client-side enum — the
dropdown options come live from `GET /onboarding/lookups/leadSource`, and
GP's own validation is the source of truth for which codes are acceptable
(same posture as `association`, which also has no hardcoded option list on
this side beyond its format rule). `salesRep` is GP's own Integer type.

The response shares `SectionSaveResponse` with every other
`PUT /onboarding/{section}` — no section-specific response fields needed.
"""

from __future__ import annotations

from pydantic import BaseModel, field_validator


class ApplicationSetupRequest(BaseModel):
    """`PUT /onboarding/application-setup` request body."""

    association: str
    leadSource: str
    salesRep: int

    @field_validator("association")
    @classmethod
    def _validate_association(cls, v: str) -> str:
        if not (len(v) == 6 and v.isdigit()):
            raise ValueError("association must be exactly 6 digits")
        if v.startswith("7"):
            raise ValueError("association must not start with 7")
        return v

    @field_validator("leadSource")
    @classmethod
    def _validate_lead_source(cls, v: str) -> str:
        if not v:
            raise ValueError("leadSource is required")
        return v

    @field_validator("salesRep")
    @classmethod
    def _validate_sales_rep(cls, v: int) -> int:
        if v <= 0:
            raise ValueError("salesRep must be a positive integer")
        return v
