// Copyright (C) 2024 veypi <i@veypi.com>
// 2025-03-04 16:08:06
// Distributed under terms of the MIT license.

package org

import (
	"github.com/veypi/vbase/cfg"
	"github.com/veypi/vbase/models"
	"github.com/veypi/vigo"
)

type DeleteRequest struct {
	OrgID string `src:"path@org_id" desc:"组织ID"`
}

func del(x *vigo.X, req *DeleteRequest) error {
	var org models.Org
	if err := cfg.DB().First(&org, "id = ?", req.OrgID).Error; err != nil {
		return vigo.ErrNotFound
	}

	if err := cfg.DB().Delete(&org).Error; err != nil {
		return vigo.ErrInternalServer.WithError(err)
	}

	return nil
}
