# Category

**Kind:** Class

**Source:** `Pams/Logic/Pams.Business/Entity/Common/Category.Model.cs` (line 14)

**Part of:** [Pams](subsystem-pams)

`Category` is a C# entity model for storing category records and their parent-child relationships. It supports optional company scoping through `CompanyId` and represents hierarchy through `ParentId` and `HasChilds`.

## Diagram

```mermaid
graph LR
  Category[Category]
  Category --> Id[Id: long]
  Category --> CompanyId[CompanyId: int?]
  Category --> ParentId[ParentId: long?]
  Category --> CategoryName[CategoryName: string]
  Category --> ReferenceNo[ReferenceNo: string]
  Category --> HasChilds[HasChilds: bool]

  ParentId --> ParentCategory[Parent Category]
  CompanyId --> Company[Company]
```

## Usage

```ts
type Category = {
  id: number;
  companyId: number | null;
  parentId: number | null;
  categoryName: string;
  referenceNo: string;
  hasChilds: boolean;
};

const category: Category = {
  id: 100,
  companyId: 10,
  parentId: null,
  categoryName: "Office Supplies",
  referenceNo: "OFFICE",
  hasChilds: true,
};

async function createCategory(category: Category) {
  const response = await fetch("/api/categories", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(category),
  });

  return response.json();
}

createCategory(category);
```

## AI Coding Instructions

- Preserve the `HasChilds` property name when mapping API payloads, even though it differs from the usual `HasChildren` spelling.
- Treat `CompanyId` and `ParentId` as nullable values when creating or updating categories.
- Use `ParentId` to represent category hierarchy; use `null` for a root category.
- Keep `HasChilds` consistent with the presence of child category records when category trees are created or updated.
- Map C# PascalCase property names to the API naming convention used by the application.

## Relationships

- IMPORTS → `CategoryPrincipal`
- IMPORTS → `CategoryPrincipalBindingModel`
- IMPORTS → `Category`
- IMPORTS → `EntityBase`
- IMPORTS → `PamsLinqDataContext`

## Used by

14 references from 14 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

### Imported by (14)

- `BookingTargetController` — `Pams/API/Pams.API/Controllers/Common/BookingTargetController.cs`:28
- `LostReasonController` — `Pams/API/Pams.API/Controllers/Common/LostReasonController.cs`:29
- `MarketSegmentController` — `Pams/API/Pams.API/Controllers/Common/MarketSegmentController.cs`:21
- `CanceledController` — `Pams/API/Pams.API/Controllers/Sales/CanceledController.cs`:26
- `DeliveredController` — `Pams/API/Pams.API/Controllers/Sales/DeliveredController.cs`:26
- `InquiryController` — `Pams/API/Pams.API/Controllers/Sales/InquiryController.cs`:48
- `OfferController` — `Pams/API/Pams.API/Controllers/Sales/OfferController.cs`:23
- `OrderController` — `Pams/API/Pams.API/Controllers/Sales/OrderController.cs`:23

…and 6 more.
