using extension auth;

module default {
    global currentUser := (
        assert_single((
        select User
        filter .identity = global ext::auth::ClientTokenIdentity
        ))
    );

    type User {
        required setting: Setting;
        required identity: ext::auth::Identity;
    }

    type Key {
        required name: str;
        company: Company;
        required key: str;
        required date: datetime {
            default := datetime_current();
        }
    }

    type Setting {
        default_model: str;
        multi keys: Key {
            on target delete allow;
        };
    }

    type Conversation {
        required name: str;
        required user: User {
            on target delete allow;
        };
        required date: datetime {
            default := datetime_current();
        }
    }

    type Area {
        required position: int64;
        required conversation: Conversation {
            on target delete delete source;
        };
    }

    type Message {
        required selected: bool;
        required role: str;
        required content: str;
        required llm: LLM;
        required area: Area {
            on target delete delete source;
        };
        required conversation: Conversation {
            on target delete delete source;
        };
        required date: datetime {
            default := datetime_current();
        }
    }

    type Usage {
        required model_id: str;
        user: User;
        required input_cost: float32; 
        required output_cost: float32; 
        required input_token: int32; 
        required output_token: int32;
        required date: datetime {
            default := datetime_current();
        }
    }

    type LLM {
        required name: str;
        required context: str;
        required temperature: float32;
        required modelInfo: ModelInfo;
        required user: User;
    }

    type Company {
        required name: str;
		required icon: str;
    }

    type ModelInfo {
        required modelID:     str;
		required name:        str;
		required maxToken:    int32;
		required inputPrice:  float32;
		required outputPrice: float32;
        required company: Company;
    }
}
