package grpc import ( "context" hav1 "gitea.nik4nao.com/nik/home-services/gen/ha/v1" "gitea.nik4nao.com/nik/home-services/ha-gateway/internal/core/domain" "gitea.nik4nao.com/nik/home-services/ha-gateway/internal/core/ports/driving" ) type LightGRPC struct { hav1.UnimplementedLightServiceServer svc driving.LightService } // NewLightGRPC constructs the gRPC adapter for LightService. func NewLightGRPC(svc driving.LightService) *LightGRPC { return &LightGRPC{svc: svc} } // TurnOn maps a protobuf turn-on request into domain parameters. func (h *LightGRPC) TurnOn(ctx context.Context, req *hav1.TurnOnRequest) (*hav1.LightResponse, error) { s, err := h.svc.TurnOn(ctx, protoTurnOnToParams(req)) if err != nil { return nil, grpcError(err) } return &hav1.LightResponse{State: domainStateToProto(s)}, nil } // TurnOff maps a protobuf turn-off request into domain parameters. func (h *LightGRPC) TurnOff(ctx context.Context, req *hav1.TurnOffRequest) (*hav1.LightResponse, error) { s, err := h.svc.TurnOff(ctx, protoTurnOffToParams(req)) if err != nil { return nil, grpcError(err) } return &hav1.LightResponse{State: domainStateToProto(s)}, nil } // Toggle forwards a light toggle request to the domain service. func (h *LightGRPC) Toggle(ctx context.Context, req *hav1.ToggleRequest) (*hav1.LightResponse, error) { s, err := h.svc.Toggle(ctx, domain.EntityID(req.EntityId)) if err != nil { return nil, grpcError(err) } return &hav1.LightResponse{State: domainStateToProto(s)}, nil } // ListLights returns discovery-oriented light metadata for clients such as Discord. func (h *LightGRPC) ListLights(ctx context.Context, req *hav1.ListLightsRequest) (*hav1.ListLightsResponse, error) { lights, err := h.svc.ListLights(ctx) if err != nil { return nil, grpcError(err) } out := make([]*hav1.LightEntity, 0, len(lights)) for _, l := range lights { out = append(out, domainLightToProto(l)) } return &hav1.ListLightsResponse{Lights: out}, nil }