syntax = "v1"

import "common.api"

info (
	title:   "聚玩店铺服务"
	desc:    "管理店铺信息、员工邀请、模板配置。ID 字段（int64）以 string 传输"
	author:  "Asadz"
	version: "1.0"
)

type (
	ShopProfile {
		Id                     string      `json:"id"`
		Owner                  UserProfile `json:"owner"`
		Name                   string      `json:"name"`
		Banner                 string      `json:"banner,optional"`
		Description            string      `json:"description"`
		Rating                 string      `json:"rating"`
		TotalOrders            int64       `json:"totalOrders"`
		PlayerCount            int64       `json:"playerCount"`
		CommissionType         string      `json:"commissionType"`
		CommissionValue        string      `json:"commissionValue"`
		AllowMultiShop         bool        `json:"allowMultiShop"`
		AllowIndependentOrders bool        `json:"allowIndependentOrders"`
		DispatchMode           string      `json:"dispatchMode"`
		Announcements          []string    `json:"announcements"`
		TemplateConfig         interface{} `json:"templateConfig"`
	}
	ShopListResp {
		Items []ShopProfile `json:"items"`
		Meta  PageMeta      `json:"meta"`
	}
	CreateShopReq {
		Name            string `json:"name"`
		Description     string `json:"description"`
		CommissionType  string `json:"commissionType"`
		CommissionValue string `json:"commissionValue"`
	}
	UpdateShopReq {
		Id                     int64  `path:"id"`
		Name                   string `json:"name,optional"`
		Description            string `json:"description,optional"`
		CommissionType         string `json:"commissionType,optional"`
		CommissionValue        string `json:"commissionValue,optional"`
		AllowMultiShop         bool   `json:"allowMultiShop,optional"`
		AllowIndependentOrders bool   `json:"allowIndependentOrders,optional"`
		DispatchMode           string `json:"dispatchMode,optional"`
	}
	UpdateTemplateReq {
		Id       int64  `path:"id"`
		Sections string `json:"sections"`
	}
	AnnouncementReq {
		Id      int64  `path:"id"`
		Content string `json:"content"`
	}
	IncomeStatsResp {
		MonthlyIncome     string `json:"monthlyIncome"`
		PendingSettlement string `json:"pendingSettlement"`
		TotalWithdrawn    string `json:"totalWithdrawn"`
		TotalOrders       int64  `json:"totalOrders"`
		CompletedOrders   int64  `json:"completedOrders"`
	}
	InvitationReq {
		Id       int64 `path:"id"`
		PlayerId int64 `json:"playerId,string"`
	}
)

type (
	ShopIdReq {
		Id int64 `path:"id"`
	}
	UserIdReq {
		Id int64 `path:"id"`
	}
)

@server (
	prefix: api/v1
	group:  shop
)
service shop-api {
	@doc "获取店铺列表"
	@handler ListShops
	get /shops (PageReq) returns (ShopListResp)

	@doc "获取店铺详情"
	@handler GetShop
	get /shops/:id (ShopIdReq) returns (ShopProfile)

	@doc "获取店长的店铺"
	@handler GetUserShop
	get /users/:id/shop (UserIdReq) returns (ShopProfile)
}

type (
	DeleteAnnouncementReq {
		Id    int64 `path:"id"`
		index int64 `path:"index"`
	}
	RemovePlayerReq {
		Id       int64 `path:"id"`
		PlayerId int64 `path:"playerId"`
	}
	AcceptInvitationReq {
		Id int64 `path:"id"`
	}
	ShopInvitation {
		Id          int64  `json:"id,string"`
		ShopId      int64  `json:"shopId,string"`
		PlayerId    int64  `json:"playerId,string"`
		Status      string `json:"status"`
		InvitedBy   int64  `json:"invitedBy,string"`
		CreatedAt   int64  `json:"createdAt"`
		RespondedAt int64  `json:"respondedAt,optional"`
	}
	ShopInvitationListResp {
		Items []ShopInvitation `json:"items"`
	}
)

@server (
	prefix: api/v1
	group:  shop
)
service shop-api {
	@doc "创建店铺"
	@handler CreateShop
	post /shops (CreateShopReq) returns (ShopProfile)

	@doc "获取当前用户的店铺"
	@handler GetMyShop
	get /shops/mine (EmptyResp) returns (ShopProfile)

	@doc "更新店铺信息"
	@handler UpdateShop
	put /shops/:id (UpdateShopReq) returns (ShopProfile)

	@doc "更新店铺模板"
	@handler UpdateShopTemplate
	put /shops/:id/template (UpdateTemplateReq) returns (EmptyResp)

	@doc "新增店铺公告"
	@handler AddAnnouncement
	post /shops/:id/announcements (AnnouncementReq) returns (EmptyResp)

	@doc "删除店铺公告"
	@handler DeleteAnnouncement
	delete /shops/:id/announcements/:index (DeleteAnnouncementReq) returns (EmptyResp)

	@doc "邀请打手"
	@handler InvitePlayer
	post /shops/:id/invitations (InvitationReq) returns (EmptyResp)

	@doc "获取店铺邀请列表"
	@handler ListShopInvitations
	get /shops/:id/invitations (ShopIdReq) returns (ShopInvitationListResp)

	@doc "获取我收到的邀请"
	@handler MyInvitations
	get /shops/invitations/mine returns (ShopInvitationListResp)

	@doc "接受邀请"
	@handler AcceptInvitation
	post /shops/invitations/:id/accept (AcceptInvitationReq) returns (EmptyResp)

	@doc "拒绝邀请"
	@handler RejectInvitation
	delete /shops/invitations/:id (AcceptInvitationReq) returns (EmptyResp)

	@doc "移除打手"
	@handler RemovePlayer
	delete /shops/:id/players/:playerId (RemovePlayerReq) returns (EmptyResp)

	@doc "获取收入统计"
	@handler GetShopIncomeStats
	get /shops/:id/income-stats (AcceptInvitationReq) returns (IncomeStatsResp)
}

