package dto

import "time"

// Project is the API wire shape for a workspace Project — the machine-attached
// resource that groups reviews and files for one workspace target. Mirrors
// agent.Project; field tags are authoritative for the browser contract.
type Project struct {
	ID              string    `json:"id"`
	WorkspaceID     string    `json:"workspaceId"`
	MachineID       string    `json:"machineId"`
	RootPath        string    `json:"rootPath"`
	Name            string    `json:"name"`
	Description     string    `json:"description"`
	Visibility      string    `json:"visibility"`
	CurrentRole     string    `json:"currentRole"`
	OwnerUserID     string    `json:"ownerUserId"`
	CreatedByUserID string    `json:"createdByUserId,omitempty"`
	UpdatedByUserID string    `json:"updatedByUserId,omitempty"`
	CreatedAt       time.Time `json:"createdAt"`
	UpdatedAt       time.Time `json:"updatedAt"`
}

// ProjectGrant is the API wire shape for one non-owner access grant on a
// Project. Owner access is never carried here — it is derived from
// projects.owner_user_id.
type ProjectGrant struct {
	ProjectID string    `json:"projectId"`
	MemberID  string    `json:"memberId"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

// ProjectFile is one entry returned by the Project files endpoint. Project
// browsing is lazy (one directory level per request), so child aggregate
// counts are intentionally not part of this contract.
type ProjectFile struct {
	Name        string     `json:"name"`
	Path        string     `json:"path"`
	IsDirectory bool       `json:"isDirectory"`
	Size        int64      `json:"size,omitempty"`
	ModifiedAt  *time.Time `json:"modifiedAt,omitempty"`
}

// CreateProjectRequest is the request body for POST /projects. MachineID and
// RootPath are required; Visibility defaults to 'private' in the store layer.
type CreateProjectRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	MachineID   string `json:"machineId"`
	RootPath    string `json:"rootPath"`
	Visibility  string `json:"visibility,omitempty"`
}

// UpdateProjectRequest is the request body for PATCH /projects/:projectId.
// Each pointer field is optional: nil means "preserve existing". MachineID
// and RootPath are intentionally absent — they are immutable.
type UpdateProjectRequest struct {
	Name        *string `json:"name,omitempty"`
	Description *string `json:"description,omitempty"`
	Visibility  *string `json:"visibility,omitempty"`
}

// UpsertProjectGrantRequest is the request body for PUT
// /projects/:projectId/settings/access/:memberId. Role must be 'manage' or
// 'view'; 'owner' is rejected because owner is derived, never persisted.
type UpsertProjectGrantRequest struct {
	Role string `json:"role"`
}
