# generated by datamodel-codegen:
#   filename:  openapi.json
#   timestamp: 2026-02-23T21:14:17+00:00

from __future__ import annotations

from datetime import datetime
from enum import Enum
from typing import Any, Literal
from uuid import UUID

from pydantic import (
    BaseModel,
    ConfigDict,
    EmailStr,
    Field,
    PositiveFloat,
    PositiveInt,
    confloat,
    conint,
    constr,
)


class AdditionalToolCall(BaseModel):
    id: UUID | None = Field(None, title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    tool_name: str = Field(..., title='Tool Name')
    input_params: dict[str, Any] | None = Field(None, title='Input Params')
    result: dict[str, Any] | None = Field(None, title='Result')
    result_type: str | None = Field(None, title='Result Type')
    result_correlation_id: UUID | None = Field(..., title='Result Correlation Id')
    error_message: str | None = Field(..., title='Error Message')
    tool_call_time_seconds: float | None = Field(..., title='Tool Call Time Seconds')
    created_at: datetime | None = Field(None, title='Created At')


class AdditionalToolCallOut(BaseModel):
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    tool_name: str = Field(..., title='Tool Name')
    error_message: str | None = Field(..., title='Error Message')
    tool_call_time_seconds: float | None = Field(..., title='Tool Call Time Seconds')
    created_at: datetime = Field(..., title='Created At')


class AggregatedStepStatus(BaseModel):
    generation_status: dict[StepStatus, int] = Field(..., title='Generation Status')
    compilation_status: dict[StepStatus, int] = Field(..., title='Compilation Status')
    validation_status: dict[StepStatus, int] = Field(..., title='Validation Status')
    benchmarking_status: dict[StepStatus, int] = Field(..., title='Benchmarking Status')
    has_finished: bool | None = Field(False, title='Has Finished')


class AuthServerOut(BaseModel):
    url: str = Field(..., title='Url')
    application_name: str = Field(..., title='Application Name')


class BillItem(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    id: UUID = Field(..., title='Id')
    description: str = Field(..., title='Description')
    amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Amount'
    )
    price_per_unit: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Price Per Unit'
    )
    unit: str | None = Field(..., title='Unit')
    subtotal: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Subtotal'
    )
    created_at: datetime = Field(..., title='Created At')


class BillStatus(Enum):
    open = 'open'
    closed = 'closed'
    canceled = 'canceled'


class Status(Enum):
    complete = 'complete'
    expired = 'expired'
    open = 'open'


class PaymentStatus(Enum):
    no_payment_required = 'no_payment_required'
    paid = 'paid'
    unpaid = 'unpaid'


class CheckoutSession(BaseModel):
    id: str = Field(..., title='Id')
    url: str = Field(..., title='Url')
    status: Status | None = Field(..., title='Status')
    return_url: str | None = Field(..., title='Return Url')
    expires_at: int = Field(..., title='Expires At')
    created: int = Field(..., title='Created')
    currency: str | None = Field(..., title='Currency')
    payment_status: PaymentStatus = Field(..., title='Payment Status')
    success_url: str | None = Field(..., title='Success Url')
    amount_subtotal: int | None = Field(..., title='Amount Subtotal')
    amount_total: int | None = Field(..., title='Amount Total')


class CheckoutSessionCreationResponse(BaseModel):
    url: str = Field(..., title='Url')


class CommandOut(BaseModel):
    id: UUID = Field(..., title='Id')
    session_id: UUID = Field(..., title='Session Id')
    attempt_id: UUID = Field(..., title='Attempt Id')
    parent_command_id: UUID | None = Field(..., title='Parent Command Id')
    command_type: str = Field(..., title='Command Type')
    command_handler: str = Field(..., title='Command Handler')
    payload: dict[str, Any] = Field(..., title='Payload')
    result: dict[str, Any] | None = Field(..., title='Result')
    started_at: datetime = Field(..., title='Started At')
    finished_at: datetime | None = Field(..., title='Finished At')
    children_time: float | None = Field(..., title='Children Time')
    self_time: float | None = Field(..., title='Self Time')
    error_message: str | None = Field(..., title='Error Message')
    traceback: str | None = Field(..., title='Traceback')


class CreateToken(BaseModel):
    label: str = Field(..., title='Label')
    expires_at: datetime | None = Field(None, title='Expires At')


class Document(BaseModel):
    id: str = Field(..., title='Id')
    content: str | None = Field(None, title='Content')
    meta: dict[str, Any] | None = Field(None, title='Meta')
    score: float | None = Field(None, title='Score')


class DocumentSearchRequest(BaseModel):
    query: str = Field(..., title='Query')
    max_entries: conint(lt=50, gt=0) | None = Field(5, title='Max Entries')


class DocumentSearchResult(BaseModel):
    documents: list[Document] = Field(..., title='Documents')


class EvalLog(BaseModel):
    message: str = Field(..., title='Message')
    timestamp: datetime | None = Field(None, title='Timestamp')


class EvalRefMode(Enum):
    EAGER = 'EAGER'
    COMPILED = 'COMPILED'
    REDUCE_OVERHEAD = 'REDUCE_OVERHEAD'
    MAX_AUTOTUNE = 'MAX_AUTOTUNE'
    MAX_AUTOTUNE_NO_CUDAGRAPHS = 'MAX_AUTOTUNE_NO_CUDAGRAPHS'


class EvaluateKernelRequest(BaseModel):
    reference_code: str = Field(..., title='Reference Code')
    optimized_code: str = Field(..., title='Optimized Code')
    name: str | None = Field('', title='Name')
    origin: str | None = Field('user', title='Origin')
    extras: dict[str, str] | None = Field(None, title='Extras')


class ExampleProblem(BaseModel):
    problem_id: int = Field(..., title='Problem Id')
    level: int = Field(..., title='Level')
    name: str = Field(..., title='Name')
    code: str = Field(..., title='Code')


class ExampleProblemsResult(BaseModel):
    problems: list[ExampleProblem] = Field(..., title='Problems')


class ExceptionInfo(BaseModel):
    type: str = Field(..., title='Type')
    message: str = Field(..., title='Message')
    traceback: list[str] = Field(..., title='Traceback')


class ExceptionModel(BaseModel):
    exception_type: str = Field(..., title='Exception Type')
    message: str = Field(..., title='Message')
    traceback: str = Field(..., title='Traceback')
    extra_args: list[Any] | None = Field(None, title='Extra Args')


class FixSuggestion(BaseModel):
    formatted_code: str = Field(..., title='Formatted Code')
    summary: str = Field(..., title='Summary')


class FreeCreditsForNewUsersOfferParamsInput(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    offer_type: Literal['free_credits_for_new_users'] = Field(
        'free_credits_for_new_users', title='Offer Type'
    )
    free_credits_amount: (
        float | constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None
    ) = Field(None, title='Free Credits Amount')
    top_up_transaction_title: str | None = Field(
        'Initial bonus for new user', title='Top Up Transaction Title'
    )
    wallet_type: str | None = Field('default', title='Wallet Type')


class FreeCreditsForNewUsersOfferParamsOutput(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    offer_type: Literal['free_credits_for_new_users'] = Field(
        'free_credits_for_new_users', title='Offer Type'
    )
    free_credits_amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None = (
        Field(None, title='Free Credits Amount')
    )
    top_up_transaction_title: str | None = Field(
        'Initial bonus for new user', title='Top Up Transaction Title'
    )
    wallet_type: str | None = Field('default', title='Wallet Type')


class FunctionalCorrectnessResult(BaseModel):
    is_correct: bool = Field(..., title='Is Correct')
    error: str | None = Field(None, title='Error')
    output: str | None = Field(None, title='Output')
    num_correct: int | None = Field(None, title='Num Correct')
    num_total: int | None = Field(None, title='Num Total')


class GenerationModel(BaseModel):
    provider: str = Field(..., title='Provider')
    name: str = Field(..., title='Name')
    code_name: str = Field(..., title='Code Name')
    is_default: bool = Field(..., title='Is Default')


class GenerationModelsList(BaseModel):
    generation_models: list[GenerationModel] = Field(..., title='Generation Models')


class HTTPConflictError(BaseModel):
    detail: str = Field(..., title='Detail')


class HTTPForbiddenError(BaseModel):
    detail: str = Field(..., title='Detail')


class HTTPInternalServerError(BaseModel):
    detail: str = Field(..., title='Detail')


class HTTPNotFoundError(BaseModel):
    detail: str = Field(..., title='Detail')


class HTTPRequestValidationError(BaseModel):
    detail: str = Field(..., title='Detail')


class HTTPServiceUnavailableError(BaseModel):
    detail: str = Field(..., title='Detail')


class HardwareAccessRule(BaseModel):
    id: UUID | None = Field(None, title='Id')
    code_names: list[str] = Field(..., title='Code Names')
    kernel_backends: list[str] = Field(..., title='Kernel Backends')
    allowed_for_all_users: bool | None = Field(True, title='Allowed For All Users')
    allowed_user_roles: list[str] = Field(..., title='Allowed User Roles')
    allowed_user_email_domains: list[str] = Field(
        ..., title='Allowed User Email Domains'
    )
    allowed_user_ids: list[UUID] = Field(..., title='Allowed User Ids')
    disallowed_user_ids: list[UUID] = Field(..., title='Disallowed User Ids')
    priority: int | None = Field(0, title='Priority')
    enabled: bool | None = Field(True, title='Enabled')
    description: str | None = Field(None, title='Description')
    created_at: datetime | None = Field(None, title='Created At')
    updated_at: datetime | None = Field(None, title='Updated At')
    deleted_at: datetime | None = Field(None, title='Deleted At')


class HardwareAccessRuleIn(BaseModel):
    code_names: list[str] = Field(..., title='Code Names')
    kernel_backends: list[str] = Field(..., title='Kernel Backends')
    allowed_for_all_users: bool = Field(..., title='Allowed For All Users')
    allowed_user_roles: list[str] = Field(..., title='Allowed User Roles')
    allowed_user_ids: list[UUID] = Field(..., title='Allowed User Ids')
    allowed_user_email_domains: list[str] | None = Field(
        None, title='Allowed User Email Domains'
    )
    disallowed_user_ids: list[UUID] = Field(..., title='Disallowed User Ids')
    priority: int = Field(..., title='Priority')
    enabled: bool = Field(..., title='Enabled')
    description: str = Field(..., title='Description')


class HardwareAccessRuleList(BaseModel):
    rules: list[HardwareAccessRule] = Field(..., title='Rules')


class HealthCheck(BaseModel):
    status: str | None = Field('OK', title='Status')


class KernelEvaluationStatus(Enum):
    NOT_STARTED = 'NOT_STARTED'
    IN_PROGRESS = 'IN_PROGRESS'
    COMPLETED = 'COMPLETED'
    FAILED = 'FAILED'


class KernelGenerationResult(BaseModel):
    code: str = Field(..., title='Code')
    summary: str = Field(..., title='Summary')


class KernelLanguage(Enum):
    cuda = 'cuda'
    triton = 'triton'
    cutedsl = 'cutedsl'
    opencl = 'opencl'
    ripple = 'ripple'
    hip = 'hip'


class KernelProfile(BaseModel):
    raw_metrics: dict[str, Any] | None = Field(None, title='Raw Metrics')
    details_page_text: str | None = Field('', title='Details Page Text')
    source_page_text: str | None = Field('', title='Source Page Text')
    details_page_all_text: str | None = Field('', title='Details Page All Text')
    nsys_report_text: str | None = Field('', title='Nsys Report Text')
    source_sass_code: str | None = Field('', title='Source Sass Code')
    source_cuda_code: str | None = Field('', title='Source Cuda Code')
    annotated_source_file: str | None = Field('', title='Annotated Source File')
    torch_trace: str | None = Field('', title='Torch Trace')


class ListResultAdditionalToolCallOut(BaseModel):
    items: list[AdditionalToolCallOut] = Field(..., title='Items')
    total: int = Field(..., title='Total')
    limit: int | None = Field(None, title='Limit')
    offset: int | None = Field(0, title='Offset')


class ListResultCommandOut(BaseModel):
    items: list[CommandOut] = Field(..., title='Items')
    total: int = Field(..., title='Total')
    limit: int | None = Field(None, title='Limit')
    offset: int | None = Field(0, title='Offset')


class LogLevel(Enum):
    DEBUG = 'DEBUG'
    INFO = 'INFO'
    WARNING = 'WARNING'
    ERROR = 'ERROR'
    CRITICAL = 'CRITICAL'


class ManualSolutionCreationRequest(BaseModel):
    problem_id: str = Field(..., title='Problem Id')
    backend: KernelLanguage
    kernel_code: str = Field(..., title='Kernel Code')
    target_hardware: str | None = Field('nvidia:h100', title='Target Hardware')


class OfferParamsWrapper(BaseModel):
    params: FreeCreditsForNewUsersOfferParamsInput | None = Field(..., title='Params')


class OfferParamsWrapperOut(BaseModel):
    params: FreeCreditsForNewUsersOfferParamsOutput | None = Field(..., title='Params')


class OfferType(Enum):
    free_credits_for_new_users = 'free_credits_for_new_users'


class OrchestrationResult(BaseModel):
    error: ExceptionModel | None = None
    successful: bool | None = Field(None, title='Successful')
    stdout: str | None = Field('', title='Stdout')
    logs: list[EvalLog] | None = Field(None, title='Logs')
    started_at: datetime | None = Field(None, title='Started At')
    finished_at: datetime | None = Field(None, title='Finished At')


class PageUrls(BaseModel):
    terms_of_service: str = Field(..., title='Terms Of Service')
    privacy_policy: str = Field(..., title='Privacy Policy')
    contact_us: str = Field(..., title='Contact Us')


class Status1(Enum):
    canceled = 'canceled'
    processing = 'processing'
    requires_action = 'requires_action'
    requires_capture = 'requires_capture'
    requires_confirmation = 'requires_confirmation'
    requires_payment_method = 'requires_payment_method'
    succeeded = 'succeeded'


class PaymentIntentOut(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    id: str = Field(..., title='Id')
    amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Amount'
    )
    status: Status1 = Field(..., title='Status')


class PaymentMethod(BaseModel):
    id: UUID | None = Field(None, title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    payment_method_type: str = Field(..., title='Payment Method Type')
    stripe_payment_method_id: str = Field(..., title='Stripe Payment Method Id')
    card_brand: str = Field(..., title='Card Brand')
    card_last_4_digits: str | None = Field(..., title='Card Last 4 Digits')
    card_exp_month: int | None = Field(..., title='Card Exp Month')
    card_exp_year: int | None = Field(..., title='Card Exp Year')
    created_at: datetime | None = Field(None, title='Created At')
    updated_at: datetime | None = Field(None, title='Updated At')


class PaymentMethodOut(BaseModel):
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    payment_method_type: str = Field(..., title='Payment Method Type')
    card_brand: str = Field(..., title='Card Brand')
    card_last_4_digits: str | None = Field(..., title='Card Last 4 Digits')
    card_exp_month: int | None = Field(..., title='Card Exp Month')
    card_exp_year: int | None = Field(..., title='Card Exp Year')
    created_at: datetime = Field(..., title='Created At')
    updated_at: datetime = Field(..., title='Updated At')


class PaymentMethodSetupRequestOut(BaseModel):
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    stripe_checkout_session_id: str = Field(..., title='Stripe Checkout Session Id')
    wallet_id: UUID | None = Field(..., title='Wallet Id')


class PaymentMethodsOut(BaseModel):
    payment_methods: list[PaymentMethod] = Field(..., title='Payment Methods')


class ProblemCreationResponse(BaseModel):
    problem_validation_task_id: UUID = Field(..., title='Problem Validation Task Id')


class ProblemDescriptionCode(BaseModel):
    code: str = Field(..., title='Code')


class Product(Enum):
    generate_pro = 'generate_pro'


class ProfilingMode(Enum):
    compute = 'compute'
    trace = 'trace'
    full = 'full'
    torch = 'torch'


class ProfilingResult(BaseModel):
    error: ExceptionModel | None = None
    successful: bool | None = Field(None, title='Successful')
    stdout: str | None = Field('', title='Stdout')
    logs: list[EvalLog] | None = Field(None, title='Logs')
    started_at: datetime | None = Field(None, title='Started At')
    finished_at: datetime | None = Field(None, title='Finished At')
    kernel_info: list[KernelProfile] | None = Field(None, title='Kernel Info')


class Role(Enum):
    user = 'user'
    system = 'system'


class Prompt(BaseModel):
    content: str = Field(..., title='Content')
    role: Role | None = Field('user', title='Role')


class RenameInstructionRequest(BaseModel):
    new_label: str = Field(..., title='New Label')


class RenameSessionRequest(BaseModel):
    new_label: str = Field(..., title='New Label')


class SiteSettings(BaseModel):
    posthog_key: str = Field(..., title='Posthog Key')
    posthog_host: str = Field(..., title='Posthog Host')
    feedback_survey_id: str = Field(..., title='Feedback Survey Id')
    waitlist_survey_id: str = Field(..., title='Waitlist Survey Id')
    google_client_id: str = Field(..., title='Google Client Id')
    page_urls: PageUrls
    auth_server: AuthServerOut
    stripe_public_key: str = Field(..., title='Stripe Public Key')
    contact_sales_url: str = Field(..., title='Contact Sales Url')
    free_kernel_job_credits_after_signup: int | None = Field(
        ..., title='Free Kernel Job Credits After Signup'
    )


class StepStatus(Enum):
    not_started = 'not_started'
    in_progress = 'in_progress'
    completed = 'completed'
    failed = 'failed'
    cancelled = 'cancelled'


class StripePublicKey(BaseModel):
    public_key: str = Field(..., title='Public Key')


class Submission(BaseModel):
    id: UUID = Field(..., title='Id')
    problem_name: str = Field(..., title='Problem Name')
    author_name: str = Field(..., title='Author Name')
    code: str = Field(..., title='Code')
    optimized_time_ms: float = Field(..., title='Optimized Time Ms')
    attempt_id: UUID | None = Field(None, title='Attempt Id')
    target_hardware: str = Field(..., title='Target Hardware')
    kernel_backend: KernelLanguage


class SubmissionSummary(BaseModel):
    id: UUID = Field(..., title='Id')
    problem_name: str = Field(..., title='Problem Name')
    author_name: str = Field(..., title='Author Name')
    optimized_time_ms: float = Field(..., title='Optimized Time Ms')
    target_hardware: str = Field(..., title='Target Hardware')
    kernel_backend: KernelLanguage


class ThinkingLevel(Enum):
    low = 'low'
    medium = 'medium'
    high = 'high'


class Token(BaseModel):
    id: UUID | None = Field(None, title='Id')
    user_id: UUID = Field(..., title='User Id')
    label: str = Field(..., title='Label')
    token: str = Field(..., title='Token')
    created_at: datetime | None = Field(None, title='Created At')
    expires_at: datetime | None = Field(None, title='Expires At')


class TokenUsage(BaseModel):
    prompt_tokens: int = Field(..., title='Prompt Tokens')
    reasoning_tokens: int | None = Field(None, title='Reasoning Tokens')
    output_tokens: int = Field(..., title='Output Tokens')
    total_tokens: int = Field(..., title='Total Tokens')


class Tokens(BaseModel):
    tokens: list[Token] = Field(..., title='Tokens')


class TransactionRequest(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    amount: confloat(ge=0.0) | constr(
        pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,10}|(?=[\d.]{1,15}0*$)\d{0,10}\.\d{0,4}0*$)'
    ) = Field(..., description='Amount of credits', title='Amount')
    description: str = Field(..., title='Description')


class TransactionsOverTimeSpan(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    created_at: datetime = Field(..., title='Created At')
    wallet_id: UUID = Field(..., title='Wallet Id')
    top_up_sum: constr(
        pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,10}|(?=[\d.]{1,15}0*$)\d{0,10}\.\d{0,4}0*$)'
    ) = Field(..., title='Top Up Sum')
    withdrawal_sum: constr(
        pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,10}|(?=[\d.]{1,15}0*$)\d{0,10}\.\d{0,4}0*$)'
    ) = Field(..., title='Withdrawal Sum')


class Unit(Enum):
    s = 's'
    ms = 'ms'
    us = 'us'
    ns = 'ns'
    cycles = 'cycles'


class UpdateOffer(BaseModel):
    name: str = Field(..., title='Name')
    is_active: bool = Field(..., title='Is Active')
    start_time: datetime | None = Field(None, title='Start Time')
    end_time: datetime | None = Field(None, title='End Time')
    participants_limit: int = Field(..., title='Participants Limit')
    details: OfferParamsWrapper | None


class User(BaseModel):
    id: UUID = Field(..., title='Id')
    email: EmailStr = Field(..., title='Email')
    roles: list[str] | None = Field(None, title='Roles')


class UserInstruction(BaseModel):
    id: UUID = Field(..., title='Id')
    label: str = Field(..., title='Label')
    deleted_at: datetime | None = Field(..., title='Deleted At')
    thinking_level: ThinkingLevel | None = None
    user_prompt: str = Field(..., title='User Prompt')
    generation_model_name: str | None = Field(..., title='Generation Model Name')
    generation_model_nice_name: str | None = Field(
        ..., title='Generation Model Nice Name'
    )
    created_at: datetime = Field(..., title='Created At')
    stop_requested_at: datetime | None = Field(..., title='Stop Requested At')
    is_starred: bool = Field(..., title='Is Starred')


class UserRoles(BaseModel):
    roles: list[str] | None = Field(None, title='Roles')


class ValidationError(BaseModel):
    loc: list[str | int] = Field(..., title='Location')
    msg: str = Field(..., title='Message')
    type: str = Field(..., title='Error Type')
    input: Any | None = Field(None, title='Input')
    ctx: dict[str, Any] | None = Field(None, title='Context')


class ValidationResult(BaseModel):
    error: ExceptionModel | None = None
    successful: bool | None = Field(None, title='Successful')
    stdout: str | None = Field('', title='Stdout')
    logs: list[EvalLog] | None = Field(None, title='Logs')
    started_at: datetime | None = Field(None, title='Started At')
    finished_at: datetime | None = Field(None, title='Finished At')
    num_correct: int | None = Field(None, title='Num Correct')
    num_total: int | None = Field(None, title='Num Total')


class WalletAutomatedTopUp(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    active: bool = Field(..., title='Active')
    credits_threshold: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Credits Threshold'
    )
    credits_top_up_amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Credits Top Up Amount'
    )


class WalletAutomatedTopUpConfigIn(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    automated_top_up_active: bool = Field(..., title='Automated Top Up Active')
    credits_threshold: float | constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = (
        Field(..., title='Credits Threshold')
    )
    credits_top_up_amount: float | constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = (
        Field(..., title='Credits Top Up Amount')
    )


class WalletBalance(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    id: UUID = Field(..., title='Id')
    wallet_type: str = Field(..., title='Wallet Type')
    balance: constr(
        pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,10}|(?=[\d.]{1,15}0*$)\d{0,10}\.\d{0,4}0*$)'
    ) = Field(..., title='Balance')


class WalletPaymentMethodSetupRequest(BaseModel):
    set_as_default_for_wallet_id: UUID | None = Field(
        None, title='Set As Default For Wallet Id'
    )
    success_url: str = Field(..., title='Success Url')
    cancel_url: str = Field(..., title='Cancel Url')


class WalletTopUpConfigOut(BaseModel):
    id: UUID = Field(..., title='Id')
    wallet_id: UUID = Field(..., title='Wallet Id')
    payment_method: PaymentMethodOut | None
    automated_top_up: WalletAutomatedTopUp
    created_at: datetime = Field(..., title='Created At')
    updated_at: datetime = Field(..., title='Updated At')


class WalletTopUpOrder(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    amount: (
        PositiveFloat
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,12}|(?=[\d.]{1,15}0*$)\d{0,12}\.\d{0,2}0*$)'
        )
        | None
    ) = Field(0, description='Amount to top up', title='Amount')
    success_url: str = Field(..., title='Success Url')
    cancel_url: str = Field(..., title='Cancel Url')


class WalletTopUpWithPaymentMethodRequest(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    amount: (
        PositiveFloat
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,12}|(?=[\d.]{1,15}0*$)\d{0,12}\.\d{0,2}0*$)'
        )
        | None
    ) = Field(0, description='Amount to top up', title='Amount')


class WalletTransaction(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    id: UUID = Field(..., title='Id')
    amount: constr(
        pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,10}|(?=[\d.]{1,15}0*$)\d{0,10}\.\d{0,4}0*$)'
    ) = Field(..., title='Amount')
    description: str = Field(..., title='Description')
    created_at: datetime = Field(..., title='Created At')
    extra: dict[str, Any] = Field(..., title='Extra')


class WalletTransactions(BaseModel):
    transactions: list[WalletTransaction] = Field(..., title='Transactions')
    count: int = Field(..., title='Count')
    limit: int = Field(..., title='Limit')
    offset: int = Field(..., title='Offset')


class Interval(Enum):
    minute = 'minute'
    hour = 'hour'
    day = 'day'
    month = 'month'
    year = 'year'


class WalletTransactionsSummary(BaseModel):
    interval: Interval = Field(..., title='Interval')
    transactions: list[TransactionsOverTimeSpan] = Field(..., title='Transactions')
    start_time: datetime = Field(..., title='Start Time')
    end_time: datetime = Field(..., title='End Time')


class WalletType(Enum):
    default = 'default'
    kernel_gen_credits = 'kernel_gen_credits'


class Wallets(BaseModel):
    wallets: list[WalletBalance] = Field(..., title='Wallets')


class AppEvaluationEvaluationKernelInfo(BaseModel):
    name: str = Field(..., title='Name')
    source_type: str = Field(..., title='Source Type')
    decl: str = Field(..., title='Decl')
    src: str | None = Field(..., title='Src')
    asm: dict[str, str] | None = Field(None, title='Asm')


class AppEvaluationEvaluationPreparationResult(BaseModel):
    error: ExceptionModel | None = None
    successful: bool | None = Field(None, title='Successful')
    stdout: str | None = Field('', title='Stdout')
    logs: list[EvalLog] | None = Field(None, title='Logs')
    started_at: datetime | None = Field(None, title='Started At')
    finished_at: datetime | None = Field(None, title='Finished At')
    torch_kernels: list[str] | None = Field(None, title='Torch Kernels')
    runner_device_name: str | None = Field(None, title='Runner Device Name')
    runner_device_index: int | None = Field(None, title='Runner Device Index')


class AppEvaluationEvaluationStepBenchmarkingResult(BaseModel):
    benchmarked: bool = Field(..., title='Benchmarked')
    benchmarking_error: str | None = Field(None, title='Benchmarking Error')
    benchmarking_output: str | None = Field(None, title='Benchmarking Output')
    ref_time: float | None = Field(None, title='Ref Time')
    ref_time_unit: Unit | None = None
    ref_compiled_time: float | None = Field(None, title='Ref Compiled Time')
    ref_compiled_time_unit: Unit | None = None
    optimized_time: float | None = Field(None, title='Optimized Time')
    optimized_time_unit: Unit | None = None


class AppEvaluationEvaluationStepCompilationResult(BaseModel):
    compiled: bool = Field(..., title='Compiled')
    compilation_error: str | None = Field(..., title='Compilation Error')
    compilation_output: str | None = Field(..., title='Compilation Output')


class AppEvaluationEvaluationStepPreparationResult(BaseModel):
    prepared: bool = Field(..., title='Prepared')
    preparation_error: str | None = Field(..., title='Preparation Error')
    preparation_output: str | None = Field(..., title='Preparation Output')


class SourceType(Enum):
    cuda = 'cuda'
    triton = 'triton'


class LennyEvalApiResultKernelInfo(BaseModel):
    model_config = ConfigDict(
        extra='forbid',
    )
    name: str = Field(..., title='Name')
    source_type: SourceType = Field(..., title='Source Type')
    decl: str = Field(..., title='Decl')
    src: str | None = Field(..., title='Src')
    asm: dict[str, str] | None = Field(None, title='Asm')


class AgentLogEntryOut(BaseModel):
    id: UUID = Field(..., title='Id')
    agent_session_id: UUID = Field(..., title='Agent Session Id')
    attempt_id: UUID = Field(..., title='Attempt Id')
    retry_number: int = Field(..., title='Retry Number')
    level: str = Field(..., title='Level')
    message: str = Field(..., title='Message')
    exception: ExceptionInfo | None
    extra: dict[str, Any] = Field(..., title='Extra')
    source: str | None = Field(None, title='Source')
    lenny_web_version: str | None = Field(None, title='Lenny Web Version')
    created_at: datetime = Field(..., title='Created At')


class AgentSessionSummary(BaseModel):
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    owner_full_name: str = Field(..., title='Owner Full Name')
    target_hardware: str = Field(..., title='Target Hardware')
    target_language: KernelLanguage
    label: str = Field(..., title='Label')
    best_attempt_id: UUID | None = Field(None, title='Best Attempt Id')
    status: StepStatus | None = 'not_started'
    started_at: datetime = Field(..., title='Started At')
    deleted_at: datetime | None = Field(None, title='Deleted At')


class AgentSessions(BaseModel):
    sessions: list[AgentSessionSummary] = Field(..., title='Sessions')
    total: int = Field(..., title='Total')
    limit: int = Field(..., title='Limit')
    offset: int = Field(..., title='Offset')


class BestResultsByHardware(BaseModel):
    target_hardware: str = Field(..., title='Target Hardware')
    best_results: list[SubmissionSummary] = Field(..., title='Best Results')


class Bill(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    wallet_id: UUID = Field(..., title='Wallet Id')
    transaction_id: UUID = Field(..., title='Transaction Id')
    subject_type: str | None = Field(..., title='Subject Type')
    subject_id: UUID | None = Field(..., title='Subject Id')
    amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Amount'
    )
    budget_limit: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None = Field(
        ..., title='Budget Limit'
    )
    locked_amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Locked Amount'
    )
    paid_amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None = Field(
        ..., title='Paid Amount'
    )
    description: str = Field(..., title='Description')
    created_at: datetime = Field(..., title='Created At')
    updated_at: datetime = Field(..., title='Updated At')
    status: BillStatus
    items: list[BillItem] = Field(..., title='Items')


class BillInfo(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    wallet_id: UUID = Field(..., title='Wallet Id')
    transaction_id: UUID = Field(..., title='Transaction Id')
    subject_type: str | None = Field(..., title='Subject Type')
    subject_id: UUID | None = Field(..., title='Subject Id')
    amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Amount'
    )
    budget_limit: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None = Field(
        ..., title='Budget Limit'
    )
    locked_amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') = Field(
        ..., title='Locked Amount'
    )
    paid_amount: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None = Field(
        ..., title='Paid Amount'
    )
    description: str = Field(..., title='Description')
    created_at: datetime = Field(..., title='Created At')
    updated_at: datetime = Field(..., title='Updated At')
    status: BillStatus


class BillingRuleCreate(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    price_per_kernel: (
        float
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,6}|(?=[\d.]{1,11}0*$)\d{0,6}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Price Per Kernel')
    price_per_job: (
        float
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,6}|(?=[\d.]{1,11}0*$)\d{0,6}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Price Per Job')
    reservation_per_attempt: (
        float
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,6}|(?=[\d.]{1,11}0*$)\d{0,6}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Reservation Per Attempt')
    reservation_per_session: (
        float
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,6}|(?=[\d.]{1,11}0*$)\d{0,6}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Reservation Per Session')
    only_charge_when_exceeded_speedup: float | None = Field(
        None, title='Only Charge When Exceeded Speedup'
    )
    wallet_type: WalletType
    allowed_user_roles: list[str] | None = Field(None, title='Allowed User Roles')
    allowed_user_ids: list[str] | None = Field(None, title='Allowed User Ids')
    disallowed_user_ids: list[str] | None = Field(None, title='Disallowed User Ids')
    agent_types: list[str] | None = Field(None, title='Agent Types')
    priority: int | None = Field(0, title='Priority')


class BillingRuleInfo(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    id: UUID = Field(..., title='Id')
    price_per_kernel: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None = Field(
        ..., title='Price Per Kernel'
    )
    price_per_job: constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None = Field(
        ..., title='Price Per Job'
    )
    reservation_per_attempt: (
        constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None
    ) = Field(..., title='Reservation Per Attempt')
    reservation_per_session: (
        constr(pattern=r'^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$') | None
    ) = Field(..., title='Reservation Per Session')
    only_charge_when_exceeded_speedup: float | None = Field(
        ..., title='Only Charge When Exceeded Speedup'
    )
    wallet_type: WalletType
    allowed_user_roles: list[str] | None = Field(..., title='Allowed User Roles')
    allowed_user_ids: list[str] | None = Field(..., title='Allowed User Ids')
    disallowed_user_ids: list[str] | None = Field(..., title='Disallowed User Ids')
    agent_types: list[str] | None = Field(..., title='Agent Types')
    priority: int = Field(..., title='Priority')
    created_at: datetime = Field(..., title='Created At')
    updated_at: datetime = Field(..., title='Updated At')
    deleted_at: datetime | None = Field(..., title='Deleted At')


class BillingRuleUpdate(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    price_per_kernel: (
        float
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,6}|(?=[\d.]{1,11}0*$)\d{0,6}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Price Per Kernel')
    price_per_job: (
        float
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,6}|(?=[\d.]{1,11}0*$)\d{0,6}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Price Per Job')
    reservation_per_attempt: (
        float
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,6}|(?=[\d.]{1,11}0*$)\d{0,6}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Reservation Per Attempt')
    reservation_per_session: (
        float
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,6}|(?=[\d.]{1,11}0*$)\d{0,6}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Reservation Per Session')
    only_charge_when_exceeded_speedup: float | None = Field(
        None, title='Only Charge When Exceeded Speedup'
    )
    wallet_type: WalletType
    allowed_user_roles: list[str] | None = Field(None, title='Allowed User Roles')
    allowed_user_ids: list[str] | None = Field(None, title='Allowed User Ids')
    disallowed_user_ids: list[str] | None = Field(None, title='Disallowed User Ids')
    agent_types: list[str] | None = Field(None, title='Agent Types')
    priority: int = Field(..., title='Priority')


class CreateOffer(BaseModel):
    type: OfferType
    name: str = Field(..., title='Name')
    is_active: bool = Field(..., title='Is Active')
    start_time: datetime | None = Field(None, title='Start Time')
    end_time: datetime | None = Field(None, title='End Time')
    participants_limit: int = Field(..., title='Participants Limit')
    details: OfferParamsWrapper | None


class CustomCheckoutSessionRequestIn(BaseModel):
    product: Product
    success_url: str = Field(..., title='Success Url')
    cancel_url: str = Field(..., title='Cancel Url')


class CustomKernelGenerationRequest(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    problem_id: UUID = Field(..., title='Problem Id')
    thinking_level: ThinkingLevel | None = 'low'
    backend: KernelLanguage | None = 'cuda'
    user_prompt: str = Field(..., title='User Prompt')
    target_hardware: str | None = Field('nvidia:h100', title='Target Hardware')
    budget_limit: (
        confloat(ge=0.0)
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,10}|(?=[\d.]{1,15}0*$)\d{0,10}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Budget Limit')
    atol: float | None = Field(0.001, description='Absolute tolerance', title='Atol')
    rtol: float | None = Field(0.001, description='Relative tolerance', title='Rtol')


class EvaluatedKernel(BaseModel):
    id: UUID = Field(..., title='Id')
    attempt_id: UUID | None = Field(..., title='Attempt Id')
    name: str = Field(..., title='Name')
    code: str = Field(..., title='Code')
    time: float | None = Field(None, title='Time')
    time_unit: Unit | None = None
    evaluation_status: KernelEvaluationStatus | None = 'NOT_STARTED'
    reference_eager: float | None = Field(None, title='Reference Eager')
    reference_eager_unit: Unit | None = None
    reference_compile: float | None = Field(None, title='Reference Compile')
    reference_compile_unit: Unit | None = None
    speed_up_eager: float | None = Field(None, title='Speed Up Eager')
    speed_up_compiled: float | None = Field(None, title='Speed Up Compiled')
    is_close_miss: bool | None = Field(None, title='Is Close Miss')
    best_atol: float | None = Field(None, title='Best Atol')
    best_rtol: float | None = Field(None, title='Best Rtol')
    created_at: datetime = Field(..., title='Created At')


class ExpertGenerateRequest(BaseModel):
    kernel_code: str = Field(..., title='Kernel Code')
    reference_code: str | None = Field(None, title='Reference Code')
    language: KernelLanguage
    target_hardware: str | None = Field(None, title='Target Hardware')
    current_speedup: float | None = Field(None, title='Current Speedup')
    benchmark_info: str | None = Field(None, title='Benchmark Info')


class GenerationStepState(BaseModel):
    state: StepStatus | None = 'not_started'
    generated_kernel: str | None = Field(None, title='Generated Kernel')
    error: str | None = Field(None, title='Error')


class HTTPValidationError(BaseModel):
    detail: list[ValidationError] | None = Field(None, title='Detail')


class HardwareModel(BaseModel):
    provider: str = Field(..., title='Provider')
    name: str = Field(..., title='Name')
    code_name: str = Field(..., title='Code Name')
    is_default: bool = Field(..., title='Is Default')
    supported_kernel_backends: list[KernelLanguage] = Field(
        ..., title='Supported Kernel Backends'
    )


class HardwareModelList(BaseModel):
    hardware_models: list[HardwareModel] = Field(..., title='Hardware Models')


class KernelGenerationDetails(BaseModel):
    id: UUID = Field(..., title='Id')
    kernel_id: UUID = Field(..., title='Kernel Id')
    owner_id: UUID = Field(..., title='Owner Id')
    session_id: UUID = Field(..., title='Session Id')
    attempt_id: UUID = Field(..., title='Attempt Id')
    created_at: datetime = Field(..., title='Created At')
    model: str = Field(..., title='Model')
    prompts: list[Prompt] = Field(..., title='Prompts')
    usage: TokenUsage | None
    generation_cost: float | None = Field(..., title='Generation Cost')
    generation_time: float | None = Field(..., title='Generation Time')


class KernelGenerationRequest(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    label: str | None = Field(..., title='Label')
    problem_name: str | None = Field(None, title='Problem Name')
    problem_id: UUID | None = Field(None, title='Problem Id')
    backend: KernelLanguage | None = 'cuda'
    thinking_level: ThinkingLevel | None = Field(None, deprecated=True)
    max_attempts: conint(ge=0, le=100) = Field(..., title='Max Attempts')
    problem_description_code: ProblemDescriptionCode
    user_prompt: str = Field(..., title='User Prompt')
    target_hardware: str | None = Field('nvidia:h100', title='Target Hardware')
    atol: float | None = Field(0.001, title='Atol')
    rtol: float | None = Field(0.001, title='Rtol')
    evolutionary_pool_size: int | None = Field(
        None, deprecated=True, title='Evolutionary Pool Size'
    )
    budget_limit: (
        constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,10}|(?=[\d.]{1,15}0*$)\d{0,10}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Budget Limit')
    model_name: str | None = Field(None, deprecated=True, title='Model Name')


class ListResultAgentLogEntryOut(BaseModel):
    items: list[AgentLogEntryOut] = Field(..., title='Items')
    total: int = Field(..., title='Total')
    limit: int | None = Field(None, title='Limit')
    offset: int | None = Field(0, title='Offset')


class ListResultBillInfo(BaseModel):
    items: list[BillInfo] = Field(..., title='Items')
    total: int = Field(..., title='Total')
    limit: int | None = Field(None, title='Limit')
    offset: int | None = Field(0, title='Offset')


class LogMessage(BaseModel):
    step: str = Field(..., title='Step')
    type: StepStatus
    message: str = Field(..., title='Message')
    created_at: datetime | None = Field(None, title='Created At')


class LogMessages(BaseModel):
    messages: list[LogMessage] | None = Field(None, title='Messages')


class NewUserInstructions(BaseModel):
    label: str | None = Field(..., title='Label')
    thinking_level: ThinkingLevel | None = 'high'
    user_prompt: str = Field(..., title='User Prompt')


class OfferOut(BaseModel):
    id: UUID = Field(..., title='Id')
    type: OfferType
    name: str = Field(..., title='Name')
    is_active: bool = Field(..., title='Is Active')
    start_time: datetime | None = Field(None, title='Start Time')
    end_time: datetime | None = Field(None, title='End Time')
    participants_limit: int = Field(..., title='Participants Limit')
    participants_count: int = Field(..., title='Participants Count')
    out_of_stock: bool = Field(..., title='Out Of Stock')
    created_at: datetime = Field(..., title='Created At')
    updated_at: datetime = Field(..., title='Updated At')
    details: OfferParamsWrapperOut | None


class OffersList(BaseModel):
    offers: list[OfferOut] = Field(..., title='Offers')


class PredefinedKernelGenerationRequest(BaseModel):
    model_config = ConfigDict(
        regex_engine="python-re",
    )
    label: str | None = Field(..., title='Label')
    problem_id: str = Field(..., title='Problem Id')
    thinking_level: ThinkingLevel | None = 'low'
    backend: KernelLanguage | None = 'cuda'
    user_prompt: str = Field(..., title='User Prompt')
    target_hardware: str | None = Field('nvidia:h100', title='Target Hardware')
    budget_limit: (
        confloat(ge=0.0)
        | constr(
            pattern=r'^(?!^[-+.]*$)[+-]?0*(?:\d{0,10}|(?=[\d.]{1,15}0*$)\d{0,10}\.\d{0,4}0*$)'
        )
        | None
    ) = Field(None, title='Budget Limit')
    atol: float | None = Field(0.001, description='Absolute tolerance', title='Atol')
    rtol: float | None = Field(0.001, description='Relative tolerance', title='Rtol')


class Problem(BaseModel):
    id: UUID = Field(..., title='Id')
    name: str = Field(..., title='Name')
    owner_id: UUID = Field(..., title='Owner Id')
    problem_description_code: ProblemDescriptionCode


class ProblemCreationRequest(BaseModel):
    problem_name: str = Field(..., title='Problem Name')
    problem_description_code: ProblemDescriptionCode
    target_hardware: str | None = Field('nvidia:h100', title='Target Hardware')
    enable_fix_suggestions: bool | None = Field(False, title='Enable Fix Suggestions')


class ProblemLeaderboard(BaseModel):
    problem_name: str = Field(..., title='Problem Name')
    results: list[BestResultsByHardware] = Field(..., title='Results')


class ProblemValidationTaskInfo(BaseModel):
    id: UUID = Field(..., title='Id')
    request: ProblemCreationRequest
    status: StepStatus
    problem_id: UUID | None = Field(..., title='Problem Id')
    started_at: datetime = Field(..., title='Started At')
    last_update_at: datetime = Field(..., title='Last Update At')
    finished_at: datetime | None = Field(None, title='Finished At')


class ProblemValidationTaskStatus(BaseModel):
    id: UUID = Field(..., title='Id')
    request: ProblemCreationRequest
    status: StepStatus
    problem_id: UUID | None = Field(..., title='Problem Id')
    error_logs: list[LogMessage] | None = Field(None, title='Error Logs')
    compilation_status: StepStatus | None = 'not_started'
    compilation_result: AppEvaluationEvaluationStepCompilationResult | None = None
    preparation_status: StepStatus | None = 'not_started'
    preparation_result: AppEvaluationEvaluationStepPreparationResult | None = None
    benchmarking_status: StepStatus | None = 'not_started'
    benchmarking_result: AppEvaluationEvaluationStepBenchmarkingResult | None = None
    fix_suggestions: FixSuggestion | None = None
    started_at: datetime = Field(..., title='Started At')
    last_update_at: datetime = Field(..., title='Last Update At')
    finished_at: datetime | None = Field(None, title='Finished At')


class ProfileKernelRequest(BaseModel):
    reference_code: str = Field(..., title='Reference Code')
    optimized_code: str = Field(..., title='Optimized Code')
    name: str | None = Field('', title='Name')
    origin: str | None = Field('user', title='Origin')
    extras: dict[str, str] | None = Field(None, title='Extras')
    mode: ProfilingMode | None = 'compute'


class StoppedUserInstructionsResponse(BaseModel):
    stopped_instructions: list[UserInstruction] = Field(
        ..., title='Stopped Instructions'
    )


class TimingStats(BaseModel):
    mean: PositiveFloat = Field(..., title='Mean')
    std: confloat(ge=0.0) = Field(..., title='Std')
    min: PositiveFloat = Field(..., title='Min')
    max: PositiveFloat = Field(..., title='Max')
    median: PositiveFloat = Field(..., title='Median')
    num_trials: PositiveInt = Field(..., title='Num Trials')
    outliers: list[PositiveFloat] | None = Field(None, title='Outliers')
    all_values: list[PositiveFloat] | None = Field(None, title='All Values')
    unit: Unit | None = 'ms'


class UserData(BaseModel):
    id: UUID | None = Field(None, title='Id')
    email: str = Field(..., title='Email')
    full_name: str | None = Field(None, title='Full Name')
    is_active: bool | None = Field(False, title='Is Active')
    is_superuser: bool | None = Field(False, title='Is Superuser')
    roles: UserRoles
    created_at: datetime | None = Field(None, title='Created At')


class UsersOut(BaseModel):
    users: list[UserData] = Field(..., title='Users')
    count: int = Field(..., title='Count')


class AppEvaluationEvaluationCompilationResult(BaseModel):
    error: ExceptionModel | None = None
    successful: bool | None = Field(None, title='Successful')
    stdout: str | None = Field('', title='Stdout')
    logs: list[EvalLog] | None = Field(None, title='Logs')
    started_at: datetime | None = Field(None, title='Started At')
    finished_at: datetime | None = Field(None, title='Finished At')
    fast_level: int | None = Field(2, title='Fast Level')
    targets: list[str] | None = Field(None, title='Targets')
    kernels: list[AppEvaluationEvaluationKernelInfo] | None = Field(
        None, title='Kernels'
    )


class AllLeaderboards(BaseModel):
    leaderboards: list[ProblemLeaderboard] = Field(..., title='Leaderboards')


class AttemptKernels(BaseModel):
    id: UUID = Field(..., title='Id')
    attempt_number: int = Field(..., title='Attempt Number')
    status: StepStatus
    started_at: datetime = Field(..., title='Started At')
    kernels: list[EvaluatedKernel] = Field(..., title='Kernels')


class EvaluationStepState(BaseModel):
    state: StepStatus | None = 'not_started'
    is_compiled: bool | None = Field(None, title='Is Compiled')
    is_correct: bool | None = Field(None, title='Is Correct')
    error: str | None = Field(None, title='Error')
    compilation_status: StepStatus | None = 'not_started'
    compilation_result: AppEvaluationEvaluationStepCompilationResult | None = None
    preparation_status: StepStatus | None = 'not_started'
    preparation_result: AppEvaluationEvaluationStepPreparationResult | None = None
    functional_correctness_status: StepStatus | None = 'not_started'
    functional_correctness_result: FunctionalCorrectnessResult | None = None
    benchmarking_status: StepStatus | None = 'not_started'
    benchmarking_result: AppEvaluationEvaluationStepBenchmarkingResult | None = None
    kernels: list[LennyEvalApiResultKernelInfo] | None = Field(None, title='Kernels')
    log_messages: LogMessages | None = None


class KernelProfilingRun(BaseModel):
    id: UUID | None = Field(None, title='Id')
    kernel_id: UUID = Field(..., title='Kernel Id')
    owner_id: UUID = Field(..., title='Owner Id')
    session_id: UUID | None = Field(..., title='Session Id')
    attempt_id: UUID | None = Field(..., title='Attempt Id')
    target_hardware: str = Field(..., title='Target Hardware')
    eval_request: dict[str, Any] | None = Field(None, title='Eval Request')
    mode: ProfilingMode | None = 'compute'
    eval_config: dict[str, Any] | None = Field(None, title='Eval Config')
    orchestration_result: OrchestrationResult | None = None
    compilation_result: AppEvaluationEvaluationCompilationResult | None = None
    preparation_result: AppEvaluationEvaluationPreparationResult | None = None
    profiling_result: ProfilingResult | None = None
    created_at: datetime | None = Field(None, title='Created At')
    updated_at: datetime | None = Field(None, title='Updated At')
    started_at: datetime | None = Field(None, title='Started At')
    finished_at: datetime | None = Field(None, title='Finished At')
    status: KernelEvaluationStatus | None = 'NOT_STARTED'


class KernelTiming(BaseModel):
    kernel: TimingStats
    submission: TimingStats | None = None


class ListResultProblemValidationTaskInfo(BaseModel):
    items: list[ProblemValidationTaskInfo] = Field(..., title='Items')
    total: int = Field(..., title='Total')
    limit: int | None = Field(None, title='Limit')
    offset: int | None = Field(0, title='Offset')


class ManualSolutionStatus(BaseModel):
    id: UUID = Field(..., title='Id')
    status: StepStatus | None = 'not_started'
    evaluation_state: EvaluationStepState | None = None
    submission_id: UUID | None = Field(None, title='Submission Id')


class NewAttemptRequest(BaseModel):
    user_instruction: NewUserInstructions
    parent_attempt_id: UUID | None = Field(None, title='Parent Attempt Id')


class SessionKernels(BaseModel):
    owner_id: UUID = Field(..., title='Owner Id')
    session_id: UUID = Field(..., title='Session Id')
    attempts: list[AttemptKernels] = Field(..., title='Attempts')
    total_attempts: int = Field(..., title='Total Attempts')
    best_time: float | None = Field(None, title='Best Time')
    best_speedup_eager: float | None = Field(None, title='Best Speedup Eager')
    best_speedup_compiled: float | None = Field(None, title='Best Speedup Compiled')


class AgentGenerationAttempt(BaseModel):
    id: UUID = Field(..., title='Id')
    agent_session_id: UUID = Field(..., title='Agent Session Id')
    attempt_number: int = Field(..., title='Attempt Number')
    started_at: datetime = Field(..., title='Started At')
    last_update_at: datetime = Field(..., title='Last Update At')
    finished_at: datetime | None = Field(..., title='Finished At')
    status: StepStatus | None = 'not_started'
    request: KernelGenerationRequest = Field(..., deprecated=True)
    user_instruction: UserInstruction | None = None
    generation_state: GenerationStepState = Field(..., deprecated=True)
    evaluation_state: EvaluationStepState = Field(..., deprecated=True)
    evolutionary_pool_status: AggregatedStepStatus | None = Field(None, deprecated=True)
    best_kernel_id: UUID | None = Field(None, title='Best Kernel Id')
    stop_requested_at: datetime | None = Field(None, title='Stop Requested At')
    stop_reason: str | None = Field(None, title='Stop Reason')


class AgentSession(BaseModel):
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    label: str = Field(..., title='Label')
    generation_attempts: list[AgentGenerationAttempt] = Field(
        ..., deprecated=True, title='Generation Attempts'
    )
    started_at: datetime = Field(..., title='Started At')
    last_update_at: datetime = Field(..., title='Last Update At')
    stopped_at: datetime | None = Field(None, title='Stopped At')
    request: KernelGenerationRequest
    generation_state: GenerationStepState = Field(..., deprecated=True)
    evaluation_state: EvaluationStepState = Field(..., deprecated=True)
    best_kernel: EvaluatedKernel | None = None
    target_hardware: str = Field(..., title='Target Hardware')
    attempts_count: int | None = Field(0, title='Attempts Count')
    stop_requested_at: datetime | None = Field(None, title='Stop Requested At')
    status: StepStatus | None = 'not_started'
    deleted_at: datetime | None = Field(None, title='Deleted At')


class BaselineBenchmarkResult(BaseModel):
    mode: EvalRefMode
    results: list[KernelTiming] = Field(..., title='Results')


class KernelProfilingDetails(BaseModel):
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    session_id: UUID | None = Field(..., title='Session Id')
    attempt_id: UUID | None = Field(..., title='Attempt Id')
    extras: dict[str, str] = Field(..., title='Extras')
    name: str = Field(..., title='Name')
    code: str = Field(..., title='Code')
    origin: str = Field(..., title='Origin')
    created_at: datetime = Field(..., title='Created At')
    kernel_profiling_run: KernelProfilingRun | None


class AppEvaluationEvaluationBenchmarkingResult(BaseModel):
    error: ExceptionModel | None = None
    successful: bool | None = Field(None, title='Successful')
    stdout: str | None = Field('', title='Stdout')
    logs: list[EvalLog] | None = Field(None, title='Logs')
    started_at: datetime | None = Field(None, title='Started At')
    finished_at: datetime | None = Field(None, title='Finished At')
    ref_times: list[BaselineBenchmarkResult] | None = Field(None, title='Ref Times')
    user_times: list[KernelTiming] | None = Field(None, title='User Times')


class KernelEvaluation(BaseModel):
    id: UUID | None = Field(None, title='Id')
    kernel_id: UUID = Field(..., title='Kernel Id')
    owner_id: UUID = Field(..., title='Owner Id')
    session_id: UUID | None = Field(..., title='Session Id')
    attempt_id: UUID | None = Field(..., title='Attempt Id')
    target_hardware: str = Field(..., title='Target Hardware')
    eval_request: dict[str, Any] | None = Field(None, title='Eval Request')
    eval_config: dict[str, Any] | None = Field(None, title='Eval Config')
    orchestration_result: OrchestrationResult | None = None
    compilation_result: AppEvaluationEvaluationCompilationResult | None = None
    preparation_result: AppEvaluationEvaluationPreparationResult | None = None
    validation_result: ValidationResult | None = None
    benchmarking_result: AppEvaluationEvaluationBenchmarkingResult | None = None
    correct: bool | None = Field(None, title='Correct')
    is_close_miss: bool | None = Field(None, title='Is Close Miss')
    best_atol: float | None = Field(None, title='Best Atol')
    best_rtol: float | None = Field(None, title='Best Rtol')
    reference_kernel_id: UUID | None = Field(None, title='Reference Kernel Id')
    reference_time: float | None = Field(None, title='Reference Time')
    reference_time_unit: Unit | None = None
    reference_eager_time: float | None = Field(None, title='Reference Eager Time')
    reference_eager_time_unit: Unit | None = None
    optimized_time: float | None = Field(None, title='Optimized Time')
    optimized_time_unit: Unit | None = None
    speedup: float | None = Field(None, title='Speedup')
    atol: float | None = Field(0.001, title='Atol')
    rtol: float | None = Field(0.001, title='Rtol')
    created_at: datetime | None = Field(None, title='Created At')
    updated_at: datetime | None = Field(None, title='Updated At')
    started_at: datetime | None = Field(None, title='Started At')
    finished_at: datetime | None = Field(None, title='Finished At')
    status: KernelEvaluationStatus | None = 'NOT_STARTED'


class KernelEvaluationDetails(BaseModel):
    id: UUID = Field(..., title='Id')
    owner_id: UUID = Field(..., title='Owner Id')
    session_id: UUID | None = Field(..., title='Session Id')
    attempt_id: UUID | None = Field(..., title='Attempt Id')
    extras: dict[str, str] = Field(..., title='Extras')
    name: str = Field(..., title='Name')
    code: str = Field(..., title='Code')
    origin: str = Field(..., title='Origin')
    created_at: datetime = Field(..., title='Created At')
    evaluation: KernelEvaluation | None
