func (org *Organization) AccountToUserMapping(csp cloud.CSP) map[string]string {
	result := make(map[string]string)
	for _, employee := range org.Employees {
		switch csp {
		case cloud.AWS:
			for _, account := range employee.AWSAccounts {
				result[account.ID] = employee.Username
			}
		case cloud.GCP:
			for _, project := range employee.GCPProjects {
				result[project.ID] = employee.Username
			}
		}
	}
	return result
}
AccountToUserMapping is a helper method that maps accounts to their owners
username. This is useful for sending out emails to the owner of an account.
package cloudsweeper
import (
	"encoding/json"
	"fmt"
	"github.com/cloudtools/cloudsweeper/cloud"
)
type Organization struct {
	Managers    Employees   `json:"-"`
	ManagerIDs  []managerID `json:"managers"`
	Departments Departments `json:"departments"`
	Employees   Employees   `json:"employees"`
	managerMapping    map[string]*Employee
	departmentMapping map[string]*Department
	employeeMapping   map[string]*Employee
	managerEmployees  map[string]Employees
}
type managerID struct {
	ID string `json:"username"`
}
type Department struct {
	Number int    `json:"number"`
	ID     string `json:"id"`
	Name   string `json:"name"`
}
type Departments []*Department
type Employee struct {
	Username     string      `json:"username"`
	RealName     string      `json:"real_name"`
	ManagerID    string      `json:"manager"`
	Manager      *Employee   `json:"-"`
	DepartmentID string      `json:"department"`
	Department   *Department `json:"-"`
	Disabled     bool        `json:"disabled,omitempty"`
	AWSAccounts  AWSAccounts `json:"aws_accounts"`
	GCPProjects  GCPProjects `json:"gcp_projects"`
}
type Employees []*Employee
type AWSAccount struct {
	ID                  string `json:"id"`
	CloudsweeperEnabled bool   `json:"cloudsweeper_enabled,omitempty"`
}
type AWSAccounts []*AWSAccount
type GCPProject struct {
	ID                  string `json:"id"`
	CloudsweeperEnabled bool   `json:"cloudsweeper_enabled,omitempty"`
}
type GCPProjects []*GCPProject
func InitOrganization(orgData []byte) (*Organization, error) {
	org := new(Organization)
	err := json.Unmarshal(orgData, org)
	if err != nil {
		return nil, err
	}
	org.departmentMapping = make(map[string]*Department, len(org.Departments))
	for i := range org.Departments {
		org.departmentMapping[org.Departments[i].ID] = org.Departments[i]
	}
	org.employeeMapping = make(map[string]*Employee, len(org.Employees))
	for i := range org.Employees {
		org.employeeMapping[org.Employees[i].Username] = org.Employees[i]
		if department, exist := org.departmentMapping[org.Employees[i].DepartmentID]; exist {
			org.Employees[i].Department = department
		} else {
		}
	}
	org.managerMapping = make(map[string]*Employee, len(org.Managers))
	org.Managers = Employees{}
	for i := range org.ManagerIDs {
		if manager, exist := org.employeeMapping[org.ManagerIDs[i].ID]; exist {
			org.managerMapping[org.ManagerIDs[i].ID] = manager
		} else {
			return nil, fmt.Errorf("Manager %s is not in the list of employees", org.ManagerIDs[i])
		}
		org.Managers = append(org.Managers, org.employeeMapping[org.ManagerIDs[i].ID])
	}
	org.managerEmployees = make(map[string]Employees, len(org.Managers))
	for i := range org.Employees {
		if manager, exist := org.managerMapping[org.Employees[i].ManagerID]; exist {
			org.Employees[i].Manager = manager
			org.managerEmployees[manager.Username] = append(org.managerEmployees[manager.Username], org.Employees[i])
		} else {
		}
	}
	return org, nil
}
func (org *Organization) EmployeesForManager(manager *Employee) (Employees, error) {
	if _, isManager := org.managerMapping[manager.Username]; !isManager {
		return nil, fmt.Errorf("%s is not a manager", manager.Username)
	}
	if employees, exist := org.managerEmployees[manager.Username]; exist {
		return employees, nil
	}
	return Employees{}, nil
}
func (org *Organization) EnabledAccounts(csp cloud.CSP) []string {
	accounts := []string{}
	for _, employee := range org.Employees {
		switch csp {
		case cloud.AWS:
			for _, account := range employee.AWSAccounts {
				if account.CloudsweeperEnabled {
					accounts = append(accounts, account.ID)
				}
			}
		case cloud.GCP:
			for _, project := range employee.GCPProjects {
				if project.CloudsweeperEnabled {
					accounts = append(accounts, project.ID)
				}
			}
		}
	}
	return accounts
}