package api import ( "errors" "net/http" "time" "atlas9.dev/c/core" "atlas9.dev/c/core/iam" ) // BotKeysApi registers the API keys endpoints with the router. func BotKeysApi(mux *http.ServeMux, impl *BotKeysImpl) { mux.HandleFunc("POST /BotKeys_Create", impl.Create) mux.HandleFunc("POST /BotKeys_Get", impl.Get) mux.HandleFunc("POST /BotKeys_List", impl.List) mux.HandleFunc("POST /BotKeys_SetExpiration", impl.SetExpiration) } // BotKeys_CreateReq is the request for creating an API key. type BotKeys_CreateReq struct { Tenant core.ID Bot core.ID ExpiresAt *time.Time } // BotKeys_CreateRes is the response for creating an API key. type BotKeys_CreateRes struct { ID core.ID Tenant core.ID Bot core.ID Secret string CreatedAt time.Time ExpiresAt time.Time } type BotKeys_GetReq struct { ID core.ID Tenant core.ID } type BotKeys_GetRes struct { ID core.ID Tenant core.ID Bot core.ID CreatedAt time.Time ExpiresAt time.Time } type BotKeys_ListReq struct { Tenant core.ID Page core.PageReq } type BotKeys_ListRes struct { Page core.Page[BotKeys_ListItem] } type BotKeys_ListItem struct { ID core.ID Tenant core.ID Bot core.ID CreatedAt time.Time ExpiresAt time.Time } type BotKeys_SetExpirationReq struct { Tenant core.ID ID core.ID ExpiresAt time.Time } type BotKeys_SetExpirationRes struct{} func (r *BotKeys_CreateReq) Prepare() error { if r.Tenant.IsEmpty() { return iam.ErrTenantIDEmpty } return nil } func (r *BotKeys_GetReq) Prepare() error { return nil } func (r *BotKeys_ListReq) Prepare() error { return nil } func (r *BotKeys_SetExpirationReq) Prepare() error { if r.ID.IsEmpty() { return errors.New("ID is required") } return nil }