"""Persistence for public marketing-site intake."""
from __future__ import annotations

from typing import Optional

from sqlalchemy.ext.asyncio import AsyncSession

from src.domain.public.models import ContactInquiry


class ContactInquiryRepository:
    def __init__(self, db: AsyncSession):
        self._db = db

    async def create(
        self,
        *,
        first_name: str,
        last_name: str,
        email: str,
        company: Optional[str],
        subject: str,
        message: str,
    ) -> ContactInquiry:
        row = ContactInquiry(
            first_name=first_name,
            last_name=last_name,
            email=email,
            company=company,
            subject=subject,
            message=message,
            status="new",
        )
        self._db.add(row)
        await self._db.flush()
        await self._db.refresh(row)
        return row
