Repository: pagopa/p4pa-debt-positions
Pull request #199: feat: P4ADEV-2322 api delete debt position
Author: login: Benedetta-fabbri
Created: 2025-04-23T10:48:55Z | Merged: 2025-04-24T11:01:47Z

#### Description
<!--- Please always add a PR description as if nobody knows anything about the context these changes come from. -->
<!--- Even if we are all from our internal team, we may not be on the same page. -->
<!--- Write this PR as you were contributing to a public OSS project, where nobody knows you and you have to earn their trust. -->
<!--- This will improve our projects in the long run! Thanks. -->

#### List of Changes
<!--- Describe your changes in detail -->

#### Motivation and Context
<!--- Why is this change required? What problem does it solve? -->

#### How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, tests ran to see how -->
<!--- your change affects other areas of the code, etc. -->
- Pre-Deploy Test
  - [ ] Unit
  - [ ] Integration (Narrow)
- Post-Deploy Test
  - [ ] Isolated Microservice
  - [ ] Broader Integration
  - [ ] Acceptance
  - [ ] Performance & Load

#### Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

- [ ] PATCH - Bug fix (backwards compatible bug fixes)
- [x] MINOR - New feature (add functionality in a backwards compatible manner)
- [ ] MAJOR - Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] CHORE - Minor Change (fix or feature that don't impact the functionality e.g. Documentation or lint configuration)

#### Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.



Diff:
diff --git a/openapi/generated.openapi.json b/openapi/generated.openapi.json
index f44a21b60..f4636286b 100644
--- a/openapi/generated.openapi.json
+++ b/openapi/generated.openapi.json
@@ -5409,6 +5409,68 @@
         "security" : [ {
           "BearerAuth" : [ ]
         } ]
+      },
+      "delete" : {
+        "tags" : [ "debt-position" ],
+        "operationId" : "deleteDebtPosition",
+        "parameters" : [ {
+          "name" : "debtPositionId",
+          "in" : "path",
+          "description" : "The ID of the debt position",
+          "required" : true,
+          "schema" : {
+            "type" : "integer",
+            "format" : "int64"
+          }
+        } ],
+        "responses" : {
+          "204" : {
+            "description" : "No content"
+          },
+          "400" : {
+            "description" : "Invalid request",
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "$ref" : "#/components/schemas/DebtPositionErrorDTO"
+                }
+              }
+            }
+          },
+          "404" : {
+            "description" : "Not found",
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "$ref" : "#/components/schemas/DebtPositionErrorDTO"
+                }
+              }
+            }
+          },
+          "409" : {
+            "description" : "Conflict",
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "$ref" : "#/components/schemas/DebtPositionErrorDTO"
+                }
+              }
+            }
+          },
+          "500" : {
+            "description" : "Server Error",
+            "content" : {
+              "application/json" : {
+                "schema" : {
+                  "$ref" : "#/components/schemas/DebtPositionErrorDTO"
+                }
+              }
+            }
+          }
+        },
+        "security" : [ {
+          "BearerAuth" : [ ]
+        } ]
       }
     },
     "/debt-positions/ingestion-flow-file/{ingestionFlowFileId}" : {
@@ -5605,147 +5667,6 @@
   },
   "components" : {
     "schemas" : {
-      "DebtPositionOrigin" : {
-        "type" : "string",
-        "enum" : [ "ORDINARY", "ORDINARY_SIL", "SPONTANEOUS", "SECONDARY_ORG", "RECEIPT_FILE", "RECEIPT_PAGOPA", "REPORTING_PAGOPA" ]
-      },
-      "DebtPositionStatus" : {
-        "type" : "string",
-        "enum" : [ "TO_SYNC", "REPORTED", "PAID", "PARTIALLY_PAID", "CANCELLED", "EXPIRED", "UNPAID", "DRAFT" ]
-      },
-      "DebtPositionView" : {
-        "type" : "object",
-        "properties" : {
-          "debtPositionId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "description" : {
-            "type" : "string"
-          },
-          "debtPositionTypeOrgDescription" : {
-            "type" : "string"
-          },
-          "creationDate" : {
-            "type" : "string",
-            "format" : "date-time"
-          },
-          "status" : {
-            "$ref" : "#/components/schemas/DebtPositionStatus"
-          },
-          "debtPositionOrigin" : {
-            "$ref" : "#/components/schemas/DebtPositionOrigin"
-          },
-          "debtPositionTypeOrgId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "organizationId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
-          }
-        },
-        "required" : [ "debtPositionOrigin", "debtPositionTypeOrgDescription", "debtPositionTypeOrgId", "organizationId", "status" ]
-      },
-      "PageMetadata" : {
-        "type" : "object",
-        "properties" : {
-          "size" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "totalElements" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "totalPages" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "number" : {
-            "type" : "integer",
-            "format" : "int64"
-          }
-        }
-      },
-      "PagedModelDebtPositionView" : {
-        "type" : "object",
-        "properties" : {
-          "_embedded" : {
-            "type" : "object",
-            "properties" : {
-              "debtPositionViews" : {
-                "type" : "array",
-                "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionView"
-                }
-              }
-            }
-          },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
-          },
-          "page" : {
-            "$ref" : "#/components/schemas/PageMetadata"
-          }
-        }
-      },
-      "DebtPositionTypeOrgWithCount" : {
-        "type" : "object",
-        "properties" : {
-          "debtPositionTypeOrgId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "organizationId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "code" : {
-            "type" : "string"
-          },
-          "description" : {
-            "type" : "string"
-          },
-          "updateDate" : {
-            "type" : "string",
-            "format" : "date-time"
-          },
-          "enabledOperators" : {
-            "type" : "integer",
-            "format" : "int32"
-          },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
-          }
-        },
-        "required" : [ "code", "description", "organizationId" ]
-      },
-      "PagedModelDebtPositionTypeOrgWithCount" : {
-        "type" : "object",
-        "properties" : {
-          "_embedded" : {
-            "type" : "object",
-            "properties" : {
-              "debtPositionTypeOrgWithCounts" : {
-                "type" : "array",
-                "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionTypeOrgWithCount"
-                }
-              }
-            }
-          },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
-          },
-          "page" : {
-            "$ref" : "#/components/schemas/PageMetadata"
-          }
-        }
-      },
       "AbstractJsonSchemaPropertyObject" : {
         "type" : "object",
         "properties" : {
@@ -5881,28 +5802,6 @@
         },
         "required" : [ "syncStatusFrom", "syncStatusTo" ]
       },
-      "PagedModelPaymentOption" : {
-        "type" : "object",
-        "properties" : {
-          "_embedded" : {
-            "type" : "object",
-            "properties" : {
-              "paymentOptions" : {
-                "type" : "array",
-                "items" : {
-                  "$ref" : "#/components/schemas/PaymentOption"
-                }
-              }
-            }
-          },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
-          },
-          "page" : {
-            "$ref" : "#/components/schemas/PageMetadata"
-          }
-        }
-      },
       "PaymentOptionStatus" : {
         "type" : "string",
         "enum" : [ "TO_SYNC", "REPORTED", "PAID", "PARTIALLY_PAID", "CANCELLED", "INVALID", "EXPIRED", "UNPAID", "UNPAYABLE", "DRAFT" ]
@@ -5929,35 +5828,59 @@
           }
         }
       },
-      "CollectionModelInstallmentNoPII" : {
+      "PageMetadata" : {
+        "type" : "object",
+        "properties" : {
+          "size" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "totalElements" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "totalPages" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "number" : {
+            "type" : "integer",
+            "format" : "int64"
+          }
+        }
+      },
+      "PagedModelPaymentOption" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "installmentNoPIIs" : {
+              "paymentOptions" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/InstallmentNoPIIResponse"
+                  "$ref" : "#/components/schemas/PaymentOption"
                 }
               }
             }
           },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
+          },
+          "page" : {
+            "$ref" : "#/components/schemas/PageMetadata"
           }
         }
       },
-      "CollectionModelObject" : {
+      "CollectionModelInstallmentNoPII" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "objects" : {
+              "installmentNoPIIs" : {
                 "type" : "array",
                 "items" : {
-                  "type" : "object"
+                  "$ref" : "#/components/schemas/InstallmentNoPIIResponse"
                 }
               }
             }
@@ -5967,67 +5890,26 @@
           }
         }
       },
-      "ReceiptOriginType" : {
-        "type" : "string",
-        "enum" : [ "RECEIPT_PAGOPA", "RECEIPT_FILE", "PAYMENTS_REPORTING" ]
-      },
-      "ReceiptView" : {
-        "type" : "object",
-        "properties" : {
-          "receiptId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "paymentAmountCents" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "paymentDateTime" : {
-            "type" : "string",
-            "format" : "date-time"
-          },
-          "installmentId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "receiptOrigin" : {
-            "$ref" : "#/components/schemas/ReceiptOriginType"
-          },
-          "iuv" : {
-            "type" : "string"
-          },
-          "debtPositionTypeOrgDescription" : {
-            "type" : "string"
-          },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
-          }
-        },
-        "required" : [ "debtPositionTypeOrgDescription", "installmentId", "paymentAmountCents", "receiptOrigin" ]
-      },
-      "PagedModelReceiptView" : {
+      "CollectionModelObject" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "receiptViews" : {
+              "objects" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/ReceiptView"
+                  "type" : "object"
                 }
               }
             }
           },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
-          },
-          "page" : {
-            "$ref" : "#/components/schemas/PageMetadata"
           }
         }
       },
-      "DebtPositionTypeOrg" : {
+      "ReceiptNoPII" : {
         "type" : "object",
         "properties" : {
           "creationDate" : {
@@ -6041,109 +5923,119 @@
           "updateOperatorExternalId" : {
             "type" : "string"
           },
-          "debtPositionTypeOrgId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "debtPositionTypeId" : {
+          "receiptId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "organizationId" : {
+          "ingestionFlowFileId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "balance" : {
-            "type" : "string"
-          },
-          "code" : {
-            "type" : "string"
-          },
-          "description" : {
-            "type" : "string"
+          "receiptOrigin" : {
+            "$ref" : "#/components/schemas/ReceiptOriginType"
           },
-          "iban" : {
+          "paymentReceiptId" : {
             "type" : "string"
           },
-          "postalIban" : {
+          "noticeNumber" : {
             "type" : "string"
           },
-          "postalAccountCode" : {
+          "paymentNote" : {
             "type" : "string"
           },
-          "holderPostalCc" : {
+          "orgFiscalCode" : {
             "type" : "string"
           },
-          "orgSector" : {
+          "outcome" : {
             "type" : "string"
           },
-          "xsdDefinitionRef" : {
+          "creditorReferenceId" : {
             "type" : "string"
           },
-          "amountCents" : {
+          "paymentAmountCents" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "externalPaymentUrl" : {
+          "description" : {
             "type" : "string"
           },
-          "flagAnonymousFiscalCode" : {
-            "type" : "boolean"
+          "companyName" : {
+            "type" : "string"
           },
-          "flagMandatoryDueDate" : {
-            "type" : "boolean"
+          "officeName" : {
+            "type" : "string"
           },
-          "flagSpontaneous" : {
-            "type" : "boolean"
+          "idPsp" : {
+            "type" : "string"
           },
-          "flagNotifyIo" : {
-            "type" : "boolean"
+          "pspFiscalCode" : {
+            "type" : "string"
           },
-          "serviceId" : {
+          "pspPartitaIva" : {
             "type" : "string"
           },
-          "ioTemplateSubject" : {
+          "pspCompanyName" : {
             "type" : "string"
           },
-          "ioTemplateMessage" : {
+          "idChannel" : {
             "type" : "string"
           },
-          "flagActive" : {
-            "type" : "boolean"
+          "channelDescription" : {
+            "type" : "string"
           },
-          "flagNotifyOutcomePush" : {
-            "type" : "boolean"
+          "paymentMethod" : {
+            "type" : "string"
           },
-          "notifyOutcomePushOrgSilServiceId" : {
+          "feeCents" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "flagAmountActualization" : {
+          "paymentDateTime" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "applicationDate" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "transferDate" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "standin" : {
             "type" : "boolean"
           },
-          "amountActualizationOrgSilServiceId" : {
+          "debtorEntityType" : {
+            "$ref" : "#/components/schemas/PersonEntityType"
+          },
+          "personalDataId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "flagExternal" : {
-            "type" : "boolean"
+          "debtorFiscalCodeHash" : {
+            "type" : "string",
+            "format" : "byte"
           },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
           }
         },
-        "required" : [ "code", "debtPositionTypeId", "description", "iban", "organizationId" ]
+        "required" : [ "channelDescription", "companyName", "creditorReferenceId", "debtorEntityType", "debtorFiscalCodeHash", "description", "idChannel", "idPsp", "noticeNumber", "orgFiscalCode", "outcome", "paymentAmountCents", "paymentReceiptId", "personalDataId", "pspCompanyName", "receiptOrigin" ]
       },
-      "PagedModelDebtPositionTypeOrg" : {
+      "ReceiptOriginType" : {
+        "type" : "string",
+        "enum" : [ "RECEIPT_PAGOPA", "RECEIPT_FILE", "PAYMENTS_REPORTING" ]
+      },
+      "PagedModelReceiptNoPII" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "debtPositionTypeOrgs" : {
+              "receiptNoPIIs" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionTypeOrg"
+                  "$ref" : "#/components/schemas/ReceiptNoPII"
                 }
               }
             }
@@ -6156,25 +6048,67 @@
           }
         }
       },
-      "CollectionModelDebtPositionTypeOrg" : {
+      "DebtPositionTypeWithCount" : {
+        "type" : "object",
+        "properties" : {
+          "debtPositionTypeId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "code" : {
+            "type" : "string"
+          },
+          "description" : {
+            "type" : "string"
+          },
+          "updateDate" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "activeOrganizations" : {
+            "type" : "integer",
+            "format" : "int32"
+          },
+          "brokerId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          }
+        },
+        "required" : [ "brokerId", "code", "description" ]
+      },
+      "PagedModelDebtPositionTypeWithCount" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "debtPositionTypeOrgs" : {
+              "debtPositionTypeWithCounts" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionTypeOrg"
+                  "$ref" : "#/components/schemas/DebtPositionTypeWithCount"
                 }
               }
             }
           },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
+          },
+          "page" : {
+            "$ref" : "#/components/schemas/PageMetadata"
           }
         }
       },
+      "DebtPositionOrigin" : {
+        "type" : "string",
+        "enum" : [ "ORDINARY", "ORDINARY_SIL", "SPONTANEOUS", "SECONDARY_ORG", "RECEIPT_FILE", "RECEIPT_PAGOPA", "REPORTING_PAGOPA" ]
+      },
+      "DebtPositionStatus" : {
+        "type" : "string",
+        "enum" : [ "TO_SYNC", "REPORTED", "PAID", "PARTIALLY_PAID", "CANCELLED", "EXPIRED", "UNPAID", "DRAFT" ]
+      },
       "DebtPosition" : {
         "type" : "object",
         "properties" : {
@@ -6273,129 +6207,50 @@
           }
         }
       },
-      "ReceiptNoPII" : {
+      "ReceiptView" : {
         "type" : "object",
         "properties" : {
-          "creationDate" : {
-            "type" : "string",
-            "format" : "date-time"
-          },
-          "updateDate" : {
-            "type" : "string",
-            "format" : "date-time"
-          },
-          "updateOperatorExternalId" : {
-            "type" : "string"
-          },
           "receiptId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "ingestionFlowFileId" : {
+          "paymentAmountCents" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "receiptOrigin" : {
-            "$ref" : "#/components/schemas/ReceiptOriginType"
-          },
-          "paymentReceiptId" : {
-            "type" : "string"
-          },
-          "noticeNumber" : {
-            "type" : "string"
-          },
-          "paymentNote" : {
-            "type" : "string"
-          },
-          "orgFiscalCode" : {
-            "type" : "string"
-          },
-          "outcome" : {
-            "type" : "string"
-          },
-          "creditorReferenceId" : {
-            "type" : "string"
+          "paymentDateTime" : {
+            "type" : "string",
+            "format" : "date-time"
           },
-          "paymentAmountCents" : {
+          "installmentId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "description" : {
-            "type" : "string"
-          },
-          "companyName" : {
-            "type" : "string"
-          },
-          "officeName" : {
-            "type" : "string"
+          "receiptOrigin" : {
+            "$ref" : "#/components/schemas/ReceiptOriginType"
           },
-          "idPsp" : {
+          "iuv" : {
             "type" : "string"
           },
-          "pspFiscalCode" : {
+          "debtPositionTypeOrgDescription" : {
             "type" : "string"
           },
-          "pspPartitaIva" : {
-            "type" : "string"
-          },
-          "pspCompanyName" : {
-            "type" : "string"
-          },
-          "idChannel" : {
-            "type" : "string"
-          },
-          "channelDescription" : {
-            "type" : "string"
-          },
-          "paymentMethod" : {
-            "type" : "string"
-          },
-          "feeCents" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "paymentDateTime" : {
-            "type" : "string",
-            "format" : "date-time"
-          },
-          "applicationDate" : {
-            "type" : "string",
-            "format" : "date-time"
-          },
-          "transferDate" : {
-            "type" : "string",
-            "format" : "date-time"
-          },
-          "standin" : {
-            "type" : "boolean"
-          },
-          "debtorEntityType" : {
-            "$ref" : "#/components/schemas/PersonEntityType"
-          },
-          "personalDataId" : {
-            "type" : "integer",
-            "format" : "int64"
-          },
-          "debtorFiscalCodeHash" : {
-            "type" : "string",
-            "format" : "byte"
-          },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
           }
         },
-        "required" : [ "channelDescription", "companyName", "creditorReferenceId", "debtorEntityType", "debtorFiscalCodeHash", "description", "idChannel", "idPsp", "noticeNumber", "orgFiscalCode", "outcome", "paymentAmountCents", "paymentReceiptId", "personalDataId", "pspCompanyName", "receiptOrigin" ]
+        "required" : [ "debtPositionTypeOrgDescription", "installmentId", "paymentAmountCents", "receiptOrigin" ]
       },
-      "PagedModelReceiptNoPII" : {
+      "PagedModelReceiptView" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "receiptNoPIIs" : {
+              "receiptViews" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/ReceiptNoPII"
+                  "$ref" : "#/components/schemas/ReceiptView"
                 }
               }
             }
@@ -6408,7 +6263,7 @@
           }
         }
       },
-      "InstallmentNoPII" : {
+      "DebtPositionTypeOrg" : {
         "type" : "object",
         "properties" : {
           "creationDate" : {
@@ -6422,105 +6277,109 @@
           "updateOperatorExternalId" : {
             "type" : "string"
           },
-          "installmentId" : {
+          "debtPositionTypeOrgId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "paymentOptionId" : {
+          "debtPositionTypeId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "status" : {
-            "$ref" : "#/components/schemas/InstallmentStatus"
+          "organizationId" : {
+            "type" : "integer",
+            "format" : "int64"
           },
-          "iupdPagopa" : {
+          "balance" : {
             "type" : "string"
           },
-          "iud" : {
+          "code" : {
             "type" : "string"
           },
-          "iuv" : {
+          "description" : {
             "type" : "string"
           },
-          "iur" : {
+          "iban" : {
             "type" : "string"
           },
-          "iuf" : {
+          "postalIban" : {
             "type" : "string"
           },
-          "nav" : {
+          "postalAccountCode" : {
             "type" : "string"
           },
-          "iun" : {
+          "holderPostalCc" : {
             "type" : "string"
           },
-          "dueDate" : {
-            "type" : "string",
-            "format" : "date"
+          "orgSector" : {
+            "type" : "string"
           },
-          "notificationFeeCents" : {
-            "type" : "integer",
-            "format" : "int64"
+          "xsdDefinitionRef" : {
+            "type" : "string"
           },
           "amountCents" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "remittanceInformation" : {
+          "externalPaymentUrl" : {
             "type" : "string"
           },
-          "balance" : {
-            "type" : "string"
+          "flagAnonymousFiscalCode" : {
+            "type" : "boolean"
           },
-          "legacyPaymentMetadata" : {
-            "type" : "string"
+          "flagMandatoryDueDate" : {
+            "type" : "boolean"
           },
-          "personalDataId" : {
-            "type" : "integer",
-            "format" : "int64"
+          "flagSpontaneous" : {
+            "type" : "boolean"
           },
-          "debtorEntityType" : {
-            "$ref" : "#/components/schemas/PersonEntityType"
+          "flagNotifyIo" : {
+            "type" : "boolean"
           },
-          "debtorFiscalCodeHash" : {
-            "type" : "string",
-            "format" : "byte"
+          "serviceId" : {
+            "type" : "string"
           },
-          "syncStatus" : {
-            "$ref" : "#/components/schemas/InstallmentSyncStatus"
+          "ioTemplateSubject" : {
+            "type" : "string"
           },
-          "notificationDate" : {
-            "type" : "string",
-            "format" : "date-time"
+          "ioTemplateMessage" : {
+            "type" : "string"
           },
-          "ingestionFlowFileId" : {
-            "type" : "integer",
-            "format" : "int64"
+          "flagActive" : {
+            "type" : "boolean"
           },
-          "ingestionFlowFileLineNumber" : {
+          "flagNotifyOutcomePush" : {
+            "type" : "boolean"
+          },
+          "notifyOutcomePushOrgSilServiceId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "receiptId" : {
+          "flagAmountActualization" : {
+            "type" : "boolean"
+          },
+          "amountActualizationOrgSilServiceId" : {
             "type" : "integer",
             "format" : "int64"
           },
+          "flagExternal" : {
+            "type" : "boolean"
+          },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
           }
         },
-        "required" : [ "amountCents", "debtorEntityType", "debtorFiscalCodeHash", "iud", "paymentOptionId", "personalDataId", "remittanceInformation", "status" ]
+        "required" : [ "code", "debtPositionTypeId", "description", "iban", "organizationId" ]
       },
-      "PagedModelInstallmentNoPII" : {
+      "PagedModelDebtPositionTypeOrg" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "installmentNoPIIs" : {
+              "debtPositionTypeOrgs" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/InstallmentNoPII"
+                  "$ref" : "#/components/schemas/DebtPositionTypeOrg"
                 }
               }
             }
@@ -6533,16 +6392,16 @@
           }
         }
       },
-      "CollectionModelTransfer" : {
+      "CollectionModelDebtPositionTypeOrg" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "transfers" : {
+              "debtPositionTypeOrgs" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/TransferResponse"
+                  "$ref" : "#/components/schemas/DebtPositionTypeOrg"
                 }
               }
             }
@@ -6552,110 +6411,299 @@
           }
         }
       },
-      "InstallmentView" : {
+      "CollectionModelDebtPositionTypeOrgCountByOrganizationId" : {
         "type" : "object",
         "properties" : {
-          "installmentId" : {
+          "_embedded" : {
+            "type" : "object",
+            "properties" : {
+              "debtPositionTypeOrgCountByOrganizationIds" : {
+                "type" : "array",
+                "items" : {
+                  "$ref" : "#/components/schemas/DebtPositionTypeOrgCountByOrganizationId"
+                }
+              }
+            }
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          }
+        }
+      },
+      "DebtPositionTypeOrgCountByOrganizationId" : {
+        "type" : "object",
+        "properties" : {
+          "organizationId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "paymentOptionId" : {
+          "activeOrganizations" : {
+            "type" : "integer",
+            "format" : "int32"
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          }
+        }
+      },
+      "DebtPositionView" : {
+        "type" : "object",
+        "properties" : {
+          "debtPositionId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "iuv" : {
+          "description" : {
             "type" : "string"
           },
-          "status" : {
-            "$ref" : "#/components/schemas/InstallmentStatus"
+          "debtPositionTypeOrgDescription" : {
+            "type" : "string"
           },
-          "dueDate" : {
+          "creationDate" : {
             "type" : "string",
             "format" : "date-time"
           },
-          "amountCents" : {
+          "status" : {
+            "$ref" : "#/components/schemas/DebtPositionStatus"
+          },
+          "debtPositionOrigin" : {
+            "$ref" : "#/components/schemas/DebtPositionOrigin"
+          },
+          "debtPositionTypeOrgId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "remittanceInformation" : {
+          "organizationId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          }
+        },
+        "required" : [ "debtPositionOrigin", "debtPositionTypeOrgDescription", "debtPositionTypeOrgId", "organizationId", "status" ]
+      },
+      "PagedModelDebtPositionView" : {
+        "type" : "object",
+        "properties" : {
+          "_embedded" : {
+            "type" : "object",
+            "properties" : {
+              "debtPositionViews" : {
+                "type" : "array",
+                "items" : {
+                  "$ref" : "#/components/schemas/DebtPositionView"
+                }
+              }
+            }
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          },
+          "page" : {
+            "$ref" : "#/components/schemas/PageMetadata"
+          }
+        }
+      },
+      "DebtPositionTypeOrgWithCount" : {
+        "type" : "object",
+        "properties" : {
+          "debtPositionTypeOrgId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "organizationId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "code" : {
             "type" : "string"
           },
-          "debtorFiscalCodeHash" : {
+          "description" : {
+            "type" : "string"
+          },
+          "updateDate" : {
             "type" : "string",
-            "format" : "byte"
+            "format" : "date-time"
           },
-          "debtPositionTypeOrgDescription" : {
+          "enabledOperators" : {
+            "type" : "integer",
+            "format" : "int32"
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          }
+        },
+        "required" : [ "code", "description", "organizationId" ]
+      },
+      "PagedModelDebtPositionTypeOrgWithCount" : {
+        "type" : "object",
+        "properties" : {
+          "_embedded" : {
+            "type" : "object",
+            "properties" : {
+              "debtPositionTypeOrgWithCounts" : {
+                "type" : "array",
+                "items" : {
+                  "$ref" : "#/components/schemas/DebtPositionTypeOrgWithCount"
+                }
+              }
+            }
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          },
+          "page" : {
+            "$ref" : "#/components/schemas/PageMetadata"
+          }
+        }
+      },
+      "DebtPositionTypeOrgOperators" : {
+        "type" : "object",
+        "properties" : {
+          "creationDate" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "updateDate" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "updateOperatorExternalId" : {
             "type" : "string"
           },
+          "debtPositionTypeOrgOperatorId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "debtPositionTypeOrgId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "operatorExternalUserId" : {
+            "type" : "string"
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          }
+        },
+        "required" : [ "debtPositionTypeOrgId", "operatorExternalUserId" ]
+      },
+      "PagedModelDebtPositionTypeOrgOperators" : {
+        "type" : "object",
+        "properties" : {
+          "_embedded" : {
+            "type" : "object",
+            "properties" : {
+              "debtPositionTypeOrgOperatorses" : {
+                "type" : "array",
+                "items" : {
+                  "$ref" : "#/components/schemas/DebtPositionTypeOrgOperators"
+                }
+              }
+            }
+          },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
+          },
+          "page" : {
+            "$ref" : "#/components/schemas/PageMetadata"
           }
-        },
-        "required" : [ "amountCents", "debtPositionTypeOrgDescription", "debtorFiscalCodeHash", "paymentOptionId", "remittanceInformation", "status" ]
+        }
       },
-      "PagedModelInstallmentView" : {
+      "CollectionModelDebtPositionTypeOrgOperators" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "installmentViews" : {
+              "debtPositionTypeOrgOperatorses" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/InstallmentView"
+                  "$ref" : "#/components/schemas/DebtPositionTypeOrgOperators"
                 }
               }
             }
           },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
-          },
-          "page" : {
-            "$ref" : "#/components/schemas/PageMetadata"
           }
         }
       },
-      "DebtPositionTypeWithCount" : {
+      "DebtPositionType" : {
         "type" : "object",
         "properties" : {
+          "creationDate" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "updateDate" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "updateOperatorExternalId" : {
+            "type" : "string"
+          },
           "debtPositionTypeId" : {
             "type" : "integer",
             "format" : "int64"
           },
+          "brokerId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
           "code" : {
             "type" : "string"
           },
           "description" : {
             "type" : "string"
           },
-          "updateDate" : {
-            "type" : "string",
-            "format" : "date-time"
+          "orgType" : {
+            "type" : "string"
           },
-          "activeOrganizations" : {
-            "type" : "integer",
-            "format" : "int32"
+          "macroArea" : {
+            "type" : "string"
           },
-          "brokerId" : {
-            "type" : "integer",
-            "format" : "int64"
+          "serviceType" : {
+            "type" : "string"
+          },
+          "collectingReason" : {
+            "type" : "string"
+          },
+          "taxonomyCode" : {
+            "type" : "string"
+          },
+          "flagAnonymousFiscalCode" : {
+            "type" : "boolean"
+          },
+          "flagMandatoryDueDate" : {
+            "type" : "boolean"
+          },
+          "flagNotifyIo" : {
+            "type" : "boolean"
+          },
+          "ioTemplateMessage" : {
+            "type" : "string"
+          },
+          "ioTemplateSubject" : {
+            "type" : "string"
           },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
           }
         },
-        "required" : [ "brokerId", "code", "description" ]
+        "required" : [ "brokerId", "code", "collectingReason", "description", "macroArea", "orgType", "serviceType", "taxonomyCode" ]
       },
-      "PagedModelDebtPositionTypeWithCount" : {
+      "PagedModelDebtPositionType" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "debtPositionTypeWithCounts" : {
+              "debtPositionTypes" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionTypeWithCount"
+                  "$ref" : "#/components/schemas/DebtPositionType"
                 }
               }
             }
@@ -6747,7 +6795,7 @@
           }
         }
       },
-      "DebtPositionType" : {
+      "InstallmentNoPII" : {
         "type" : "object",
         "properties" : {
           "creationDate" : {
@@ -6761,119 +6809,105 @@
           "updateOperatorExternalId" : {
             "type" : "string"
           },
-          "debtPositionTypeId" : {
+          "installmentId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "brokerId" : {
+          "paymentOptionId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "code" : {
+          "status" : {
+            "$ref" : "#/components/schemas/InstallmentStatus"
+          },
+          "iupdPagopa" : {
             "type" : "string"
           },
-          "description" : {
+          "iud" : {
             "type" : "string"
           },
-          "orgType" : {
+          "iuv" : {
             "type" : "string"
           },
-          "macroArea" : {
+          "iur" : {
             "type" : "string"
           },
-          "serviceType" : {
+          "iuf" : {
             "type" : "string"
           },
-          "collectingReason" : {
+          "nav" : {
             "type" : "string"
           },
-          "taxonomyCode" : {
+          "iun" : {
             "type" : "string"
           },
-          "flagAnonymousFiscalCode" : {
-            "type" : "boolean"
+          "dueDate" : {
+            "type" : "string",
+            "format" : "date"
           },
-          "flagMandatoryDueDate" : {
-            "type" : "boolean"
+          "notificationFeeCents" : {
+            "type" : "integer",
+            "format" : "int64"
           },
-          "flagNotifyIo" : {
-            "type" : "boolean"
+          "amountCents" : {
+            "type" : "integer",
+            "format" : "int64"
           },
-          "ioTemplateMessage" : {
+          "remittanceInformation" : {
             "type" : "string"
           },
-          "ioTemplateSubject" : {
+          "balance" : {
             "type" : "string"
           },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
-          }
-        },
-        "required" : [ "brokerId", "code", "collectingReason", "description", "macroArea", "orgType", "serviceType", "taxonomyCode" ]
-      },
-      "PagedModelDebtPositionType" : {
-        "type" : "object",
-        "properties" : {
-          "_embedded" : {
-            "type" : "object",
-            "properties" : {
-              "debtPositionTypes" : {
-                "type" : "array",
-                "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionType"
-                }
-              }
-            }
+          "legacyPaymentMetadata" : {
+            "type" : "string"
           },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
+          "personalDataId" : {
+            "type" : "integer",
+            "format" : "int64"
           },
-          "page" : {
-            "$ref" : "#/components/schemas/PageMetadata"
-          }
-        }
-      },
-      "DebtPositionTypeOrgOperators" : {
-        "type" : "object",
-        "properties" : {
-          "creationDate" : {
+          "debtorEntityType" : {
+            "$ref" : "#/components/schemas/PersonEntityType"
+          },
+          "debtorFiscalCodeHash" : {
             "type" : "string",
-            "format" : "date-time"
+            "format" : "byte"
           },
-          "updateDate" : {
+          "syncStatus" : {
+            "$ref" : "#/components/schemas/InstallmentSyncStatus"
+          },
+          "notificationDate" : {
             "type" : "string",
             "format" : "date-time"
           },
-          "updateOperatorExternalId" : {
-            "type" : "string"
-          },
-          "debtPositionTypeOrgOperatorId" : {
+          "ingestionFlowFileId" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "debtPositionTypeOrgId" : {
+          "ingestionFlowFileLineNumber" : {
             "type" : "integer",
             "format" : "int64"
           },
-          "operatorExternalUserId" : {
-            "type" : "string"
+          "receiptId" : {
+            "type" : "integer",
+            "format" : "int64"
           },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
           }
         },
-        "required" : [ "debtPositionTypeOrgId", "operatorExternalUserId" ]
+        "required" : [ "amountCents", "debtorEntityType", "debtorFiscalCodeHash", "iud", "paymentOptionId", "personalDataId", "remittanceInformation", "status" ]
       },
-      "PagedModelDebtPositionTypeOrgOperators" : {
+      "PagedModelInstallmentNoPII" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "debtPositionTypeOrgOperatorses" : {
+              "installmentNoPIIs" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionTypeOrgOperators"
+                  "$ref" : "#/components/schemas/InstallmentNoPII"
                 }
               }
             }
@@ -6886,16 +6920,16 @@
           }
         }
       },
-      "CollectionModelDebtPositionTypeOrgOperators" : {
+      "CollectionModelTransfer" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "debtPositionTypeOrgOperatorses" : {
+              "transfers" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionTypeOrgOperators"
+                  "$ref" : "#/components/schemas/TransferResponse"
                 }
               }
             }
@@ -6905,38 +6939,66 @@
           }
         }
       },
-      "CollectionModelDebtPositionTypeOrgCountByOrganizationId" : {
+      "InstallmentView" : {
+        "type" : "object",
+        "properties" : {
+          "installmentId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "paymentOptionId" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "iuv" : {
+            "type" : "string"
+          },
+          "status" : {
+            "$ref" : "#/components/schemas/InstallmentStatus"
+          },
+          "dueDate" : {
+            "type" : "string",
+            "format" : "date-time"
+          },
+          "amountCents" : {
+            "type" : "integer",
+            "format" : "int64"
+          },
+          "remittanceInformation" : {
+            "type" : "string"
+          },
+          "debtorFiscalCodeHash" : {
+            "type" : "string",
+            "format" : "byte"
+          },
+          "debtPositionTypeOrgDescription" : {
+            "type" : "string"
+          },
+          "_links" : {
+            "$ref" : "#/components/schemas/Links"
+          }
+        },
+        "required" : [ "amountCents", "debtPositionTypeOrgDescription", "debtorFiscalCodeHash", "paymentOptionId", "remittanceInformation", "status" ]
+      },
+      "PagedModelInstallmentView" : {
         "type" : "object",
         "properties" : {
           "_embedded" : {
             "type" : "object",
             "properties" : {
-              "debtPositionTypeOrgCountByOrganizationIds" : {
+              "installmentViews" : {
                 "type" : "array",
                 "items" : {
-                  "$ref" : "#/components/schemas/DebtPositionTypeOrgCountByOrganizationId"
+                  "$ref" : "#/components/schemas/InstallmentView"
                 }
               }
             }
           },
           "_links" : {
             "$ref" : "#/components/schemas/Links"
-          }
-        }
-      },
-      "DebtPositionTypeOrgCountByOrganizationId" : {
-        "type" : "object",
-        "properties" : {
-          "organizationId" : {
-            "type" : "integer",
-            "format" : "int64"
           },
-          "activeOrganizations" : {
-            "type" : "integer",
-            "format" : "int32"
-          },
-          "_links" : {
-            "$ref" : "#/components/schemas/Links"
+          "page" : {
+            "$ref" : "#/components/schemas/PageMetadata"
           }
         }
       },
diff --git a/openapi/p4pa-debt-position.openapi.yaml b/openapi/p4pa-debt-position.openapi.yaml
index 6a17691f8..f67835700 100644
--- a/openapi/p4pa-debt-position.openapi.yaml
+++ b/openapi/p4pa-debt-position.openapi.yaml
@@ -90,6 +90,45 @@ paths:
             application/json:
               schema:
                 $ref: '#/components/schemas/DebtPositionErrorDTO'
+    delete:
+      tags:
+        - debt-position
+      operationId: deleteDebtPosition
+      parameters:
+        - name: debtPositionId
+          in: path
+          required: true
+          schema:
+            type: integer
+            format: int64
+          description: The ID of the debt position
+      responses:
+        "204":
+          description: No content
+        "400":
+          description: Invalid request
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/DebtPositionErrorDTO'
+        "404":
+          description: Not found
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/DebtPositionErrorDTO'
+        "409":
+          description: Conflict
+          content:
+            application/json:
+              schema:
+                $ref: "#/components/schemas/DebtPositionErrorDTO"
+        '500':
+          description: Server Error
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/DebtPositionErrorDTO'
   /debt-positions/ingestion-flow-file/{ingestionFlowFileId}:
     get:
       tags:
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/controller/DebtPositionControllerImpl.java b/src/main/java/it/gov/pagopa/pu/debtpositions/controller/DebtPositionControllerImpl.java
index 0e9c968f4..b651a0b2a 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/controller/DebtPositionControllerImpl.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/controller/DebtPositionControllerImpl.java
@@ -6,6 +6,7 @@
 import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
 import it.gov.pagopa.pu.debtpositions.service.InstallmentService;
 import it.gov.pagopa.pu.debtpositions.service.create.debtposition.DebtPositionCreationService;
+import it.gov.pagopa.pu.debtpositions.service.delete.DebtPositionDeletionService;
 import it.gov.pagopa.pu.debtpositions.service.installmentsync.InstallmentSynchronizeService;
 import it.gov.pagopa.pu.debtpositions.service.statusalign.DebtPositionHierarchyStatusAlignerService;
 import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionManageInstallmentsService;
@@ -31,14 +32,16 @@ public class DebtPositionControllerImpl implements DebtPositionApi {
   private final InstallmentSynchronizeService installmentSynchronizeService;
   private final InstallmentService installmentService;
   private final DebtPositionManageInstallmentsService debtPositionManageService;
+  private final DebtPositionDeletionService debtPositionDeletionService;
 
-  public DebtPositionControllerImpl(DebtPositionHierarchyStatusAlignerService debtPositionHierarchyStatusAlignerService, DebtPositionCreationService debtPositionCreationService, DebtPositionService debtPositionService, InstallmentSynchronizeService installmentSynchronizeService, InstallmentService installmentService, DebtPositionManageInstallmentsService debtPositionManageService) {
+  public DebtPositionControllerImpl(DebtPositionHierarchyStatusAlignerService debtPositionHierarchyStatusAlignerService, DebtPositionCreationService debtPositionCreationService, DebtPositionService debtPositionService, InstallmentSynchronizeService installmentSynchronizeService, InstallmentService installmentService, DebtPositionManageInstallmentsService debtPositionManageService, DebtPositionDeletionService debtPositionDeletionService) {
     this.debtPositionHierarchyStatusAlignerService = debtPositionHierarchyStatusAlignerService;
     this.debtPositionCreationService = debtPositionCreationService;
     this.debtPositionService = debtPositionService;
     this.installmentSynchronizeService = installmentSynchronizeService;
     this.installmentService = installmentService;
     this.debtPositionManageService = debtPositionManageService;
+    this.debtPositionDeletionService = debtPositionDeletionService;
   }
 
   @Override
@@ -144,4 +147,12 @@ public ResponseEntity<InstallmentDTO> updateInstallmentNotificationFee(UpdateIns
 
     return ResponseEntity.ok(installmentDTO);
   }
+
+  @Override
+  public ResponseEntity<Void> deleteDebtPosition(Long debtPositionId){
+    String accessToken = SecurityUtils.getAccessToken();
+    String operatorExternalUserId = SecurityUtils.getCurrentUserExternalId();
+    String workflowId = debtPositionDeletionService.deleteDebtPosition(debtPositionId, accessToken, operatorExternalUserId);
+    return ResponseEntity.status(HttpStatus.NO_CONTENT).header(HEADER_X_WORKFLOW_ID, workflowId).build();
+  }
 }
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/repository/BasePIIRepository.java b/src/main/java/it/gov/pagopa/pu/debtpositions/repository/BasePIIRepository.java
index 0b22a15bd..b0b0f1959 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/repository/BasePIIRepository.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/repository/BasePIIRepository.java
@@ -72,4 +72,9 @@ protected Pair<Long, Optional<P>> retrievePII(E noPii) {
     }
   }
 
+  public void delete(E noPii) {
+    personalDataService.delete(noPii.getPersonalDataId());
+    noPIIRepository.delete(noPii);
+  }
+
 }
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepository.java b/src/main/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepository.java
index f292b04b4..321e9b1b4 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepository.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepository.java
@@ -2,6 +2,7 @@
 
 import it.gov.pagopa.pu.debtpositions.dto.Installment;
 import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionOrigin;
+import it.gov.pagopa.pu.debtpositions.model.InstallmentNoPII;
 
 import java.util.List;
 
@@ -10,4 +11,6 @@ public interface InstallmentPIIRepository {
   Installment save(Installment installment);
 
   List<Installment> getByOrganizationIdAndNav(Long organizationId, String nav, List<DebtPositionOrigin> debtPositionOrigin);
+
+  void delete(InstallmentNoPII installmentNoPII);
 }
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionDeleteService.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionDeleteService.java
new file mode 100644
index 000000000..77d342fc8
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionDeleteService.java
@@ -0,0 +1,36 @@
+package it.gov.pagopa.pu.debtpositions.service;
+
+import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
+import it.gov.pagopa.pu.debtpositions.repository.*;
+import jakarta.transaction.Transactional;
+import org.springframework.stereotype.Service;
+
+@Service
+public class DebtPositionDeleteService {
+
+  private final DebtPositionRepository debtPositionRepository;
+  private final PaymentOptionRepository paymentOptionRepository;
+  private final InstallmentPIIRepository installmentPIIRepository;
+  private final TransferRepository transferRepository;
+
+  public DebtPositionDeleteService(DebtPositionRepository debtPositionRepository, PaymentOptionRepository paymentOptionRepository, InstallmentPIIRepository installmentPIIRepository, TransferRepository transferRepository) {
+    this.debtPositionRepository = debtPositionRepository;
+    this.paymentOptionRepository = paymentOptionRepository;
+    this.installmentPIIRepository = installmentPIIRepository;
+    this.transferRepository = transferRepository;
+  }
+
+  @Transactional
+  public void delete(DebtPosition debtPosition) {
+    debtPosition.getPaymentOptions()
+      .forEach(paymentOption -> {
+        paymentOption.getInstallments()
+          .forEach(installment -> {
+            installment.getTransfers().forEach(transferRepository::delete);
+            installmentPIIRepository.delete(installment);
+          });
+        paymentOptionRepository.delete(paymentOption);
+      });
+    debtPositionRepository.delete(debtPosition);
+  }
+}
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionService.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionService.java
index a77ba0441..0d9448ee7 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionService.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionService.java
@@ -11,6 +11,8 @@ public interface DebtPositionService {
   void saveDebtPosition(DebtPosition debtPosition);
   DebtPositionDTO mapDebtPosition(DebtPosition debtPosition);
   DebtPositionDTO getDebtPosition(Long debtPositionId);
+  DebtPosition getDebtPositionNoPII(Long debtPositionId);
 
   PagedDebtPositions getPagedDebtPositionsByIngestionFlowFileId(Long ingestionFlowFileId, Pageable pageable);
+  void delete(DebtPosition debtPosition);
 }
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionServiceImpl.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionServiceImpl.java
index 95e6236e0..829d942f2 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionServiceImpl.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionServiceImpl.java
@@ -16,13 +16,15 @@ public class DebtPositionServiceImpl implements DebtPositionService {
   private final DebtPositionRepository debtPositionRepository;
   private final DebtPositionSaveService debtPositionSaveService;
   private final DebtPositionMapper debtPositionMapper;
+  private final DebtPositionDeleteService debtPositionDeleteService;
 
   public DebtPositionServiceImpl(DebtPositionRepository debtPositionRepository,
                                  DebtPositionSaveService debtPositionSaveService,
-                                 DebtPositionMapper debtPositionMapper) {
+                                 DebtPositionMapper debtPositionMapper, DebtPositionDeleteService debtPositionDeleteService) {
     this.debtPositionRepository = debtPositionRepository;
     this.debtPositionSaveService = debtPositionSaveService;
     this.debtPositionMapper = debtPositionMapper;
+    this.debtPositionDeleteService = debtPositionDeleteService;
   }
 
   @Override
@@ -42,11 +44,17 @@ public DebtPositionDTO mapDebtPosition(DebtPosition debtPosition) {
 
   @Override
   public DebtPositionDTO getDebtPosition(Long debtPositionId) {
+    DebtPosition debtPosition = getDebtPositionNoPII(debtPositionId);
+    return debtPositionMapper.mapToDto(debtPosition);
+  }
+
+  @Override
+  public DebtPosition getDebtPositionNoPII(Long debtPositionId) {
     DebtPosition debtPosition = debtPositionRepository.findOneWithAllDataByDebtPositionId(debtPositionId);
     if (debtPosition == null) {
       throw new NotFoundException("DebtPosition having debtPositionId %d not found".formatted(debtPositionId));
     }
-    return debtPositionMapper.mapToDto(debtPosition);
+    return debtPosition;
   }
 
   @Override
@@ -55,5 +63,10 @@ public PagedDebtPositions getPagedDebtPositionsByIngestionFlowFileId(Long ingest
 
     return debtPositionMapper.mapToPagedDebtPositions(pagedDebtPositionsDTO);
   }
+
+  @Override
+  public void delete(DebtPosition debtPosition) {
+    debtPositionDeleteService.delete(debtPosition);
+  }
 }
 
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionService.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionService.java
new file mode 100644
index 000000000..bff5bb54a
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionService.java
@@ -0,0 +1,6 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+public interface DebtPositionDeletionService {
+
+  String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId);
+}
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
new file mode 100644
index 000000000..ee822c8a6
--- /dev/null
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
@@ -0,0 +1,93 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.connector.organization.service.OrganizationService;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.*;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.exception.custom.InvalidValueException;
+import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
+import it.gov.pagopa.pu.debtpositions.service.AuthorizeOperatorOnDebtPositionTypeService;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.debtpositions.util.InstallmentUtils;
+import it.gov.pagopa.pu.organization.dto.generated.Organization;
+import it.gov.pagopa.pu.organization.dto.generated.OrganizationStatus;
+import jakarta.transaction.Transactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DebtPositionDeletionServiceImpl implements DebtPositionDeletionService {
+
+  private final DebtPositionService debtPositionService;
+  private final OrganizationService organizationService;
+  private final AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeService;
+  private final DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService;
+
+  public DebtPositionDeletionServiceImpl(DebtPositionService debtPositionService, OrganizationService organizationService, AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeService, DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService) {
+    this.debtPositionService = debtPositionService;
+    this.organizationService = organizationService;
+    this.authorizeOperatorOnDebtPositionTypeService = authorizeOperatorOnDebtPositionTypeService;
+    this.debtPositionCancelInstallmentService = debtPositionCancelInstallmentService;
+  }
+
+  @Override
+  @Transactional
+  public String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId) {
+    log.info("Cancelling debt position having id {}", debtPositionId);
+
+    DebtPosition debtPosition = debtPositionService.getDebtPositionNoPII(debtPositionId);
+
+    if (DebtPositionStatus.DRAFT.equals(debtPosition.getStatus())) {
+      deleteDraftDebtPosition(debtPosition, accessToken, operatorExternalUserId);
+      return null;
+    }
+
+    if(isIunPresent(debtPosition)) {
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because it is been notified");
+    }
+
+    if(!InstallmentUtils.DELETABLE_DP_STATUSES.contains(debtPosition.getStatus())){
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because is not in allowed status: " + debtPosition.getStatus());
+    }
+
+    DebtPositionDTO debtPositionDTO = debtPositionService.mapDebtPosition(debtPosition);
+
+    List<InstallmentDTO> installment2operate = debtPositionDTO.getPaymentOptions().stream()
+      .map(PaymentOptionDTO::getInstallments).flatMap(Collection::stream)
+      .filter(installmentDTO -> InstallmentUtils.MODIFIABLE_STATUSES.contains(installmentDTO.getStatus()))
+      .toList();
+
+    WfExecutionParameters wfExecutionParameters = WfExecutionParameters.builder()
+      .partialChange(false)
+      .massive(false)
+      .build();
+
+    return debtPositionCancelInstallmentService.cancelInstallment(debtPositionDTO, installment2operate, wfExecutionParameters, accessToken, operatorExternalUserId);
+  }
+
+
+  private void deleteDraftDebtPosition(DebtPosition debtPosition, String accessToken, String operatorExternalUserId) {
+    Organization org = organizationService.getOrganizationById(debtPosition.getOrganizationId(), accessToken).orElseThrow(() -> new InvalidValueException("Provided organization id not found on db."));
+    if(!OrganizationStatus.ACTIVE.equals(org.getStatus())){
+      throw new InvalidValueException("Provided organization is not ACTIVE");
+    }
+    authorizeOperatorOnDebtPositionTypeService.authorize(org.getIpaCode(), debtPosition.getDebtPositionTypeOrgId(), operatorExternalUserId);
+
+    debtPositionService.delete(debtPosition);
+
+    log.info("Permanently deleted debt position with id {} having status DRAFT", debtPosition.getDebtPositionId());
+  }
+
+  private boolean isIunPresent(DebtPosition debtPosition) {
+    return debtPosition.getPaymentOptions().stream()
+      .flatMap(paymentOption -> paymentOption.getInstallments()
+        .stream())
+        .anyMatch(installment -> StringUtils.isNotBlank(installment.getIun()));
+  }
+}
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/StatusRulesHandler.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/StatusRulesHandler.java
index 4163cfd22..cba2ff225 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/StatusRulesHandler.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/StatusRulesHandler.java
@@ -10,6 +10,7 @@ public abstract class StatusRulesHandler<E extends Enum<E>, T, D> {
 
   private final E syncStatus;
   private final E paidStatus;
+  private final E draftStatus;
   private final E unpaidStatus;
   private final E expiredStatus;
   private final E cancelledStatus;
@@ -18,9 +19,10 @@ public abstract class StatusRulesHandler<E extends Enum<E>, T, D> {
   protected final Set<E> allowedCancelledStatuses;
   protected final Set<E> emptyAllowedStatuses;
 
-  protected StatusRulesHandler(E syncStatus, E paidStatus, E unpaidStatus, E expiredStatus, E cancelledStatus, E invalidStatus, E reportedStatus) {
+  protected StatusRulesHandler(E syncStatus, E paidStatus, E draftStatus, E unpaidStatus, E expiredStatus, E cancelledStatus, E invalidStatus, E reportedStatus) {
     this.syncStatus = syncStatus;
     this.paidStatus = paidStatus;
+    this.draftStatus = draftStatus;
     this.unpaidStatus = unpaidStatus;
     this.expiredStatus = expiredStatus;
     this.cancelledStatus = cancelledStatus;
@@ -57,6 +59,10 @@ public boolean isUnpaid(List<E> childrenStatusList) {
     return allMatch(childrenStatusList, unpaidStatus, allowedCancelledStatuses);
   }
 
+  public boolean isDraft(List<E> childrenStatusList) {
+    return allMatch(childrenStatusList, draftStatus, emptyAllowedStatuses);
+  }
+
   public boolean isPaid(List<E> childrenStatusList) {
     return allMatch(childrenStatusList, paidStatus, allowedCancelledStatuses);
   }
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/debtposition/DebtPositionStatusChecker.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/debtposition/DebtPositionStatusChecker.java
index 451f6441c..3120697de 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/debtposition/DebtPositionStatusChecker.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/debtposition/DebtPositionStatusChecker.java
@@ -17,7 +17,7 @@ public class DebtPositionStatusChecker extends StatusRulesHandler<PaymentOptionS
   private final DebtPositionRepository debtPositionRepository;
 
   public DebtPositionStatusChecker(DebtPositionRepository debtPositionRepository) {
-    super(TO_SYNC, PAID, UNPAID, EXPIRED, CANCELLED, INVALID, REPORTED);
+    super(TO_SYNC, PAID, DRAFT, UNPAID, EXPIRED, CANCELLED, INVALID, REPORTED);
     this.debtPositionRepository = debtPositionRepository;
   }
 
@@ -27,6 +27,8 @@ public DebtPositionStatus calculateNewStatus(List<PaymentOptionStatus> paymentOp
       return DebtPositionStatus.TO_SYNC;
     } else if (isPartiallyPaid(paymentOptionStatusList)){
       return DebtPositionStatus.PARTIALLY_PAID;
+    } else if (isDraft(paymentOptionStatusList)) {
+      return DebtPositionStatus.DRAFT;
     } else if (isUnpaid(paymentOptionStatusList)){
       return DebtPositionStatus.UNPAID;
     } else if (isPaid(paymentOptionStatusList)){
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/paymentoption/PaymentOptionStatusChecker.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/paymentoption/PaymentOptionStatusChecker.java
index f6cede4c4..ecbfc298b 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/paymentoption/PaymentOptionStatusChecker.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/statusalign/paymentoption/PaymentOptionStatusChecker.java
@@ -17,9 +17,9 @@ public class PaymentOptionStatusChecker extends StatusRulesHandler<InstallmentSt
   private final PaymentOptionRepository paymentOptionRepository;
 
   public PaymentOptionStatusChecker(PaymentOptionRepository paymentOptionRepository) {
-    super(InstallmentStatus.TO_SYNC, InstallmentStatus.PAID, InstallmentStatus.UNPAID,
-      InstallmentStatus.EXPIRED, InstallmentStatus.CANCELLED, InstallmentStatus.INVALID,
-      InstallmentStatus.REPORTED);
+    super(InstallmentStatus.TO_SYNC, InstallmentStatus.PAID, InstallmentStatus.DRAFT,
+      InstallmentStatus.UNPAID, InstallmentStatus.EXPIRED, InstallmentStatus.CANCELLED,
+      InstallmentStatus.INVALID, InstallmentStatus.REPORTED);
     this.paymentOptionRepository = paymentOptionRepository;
   }
 
@@ -31,6 +31,8 @@ public PaymentOptionStatus calculateNewStatus(List<InstallmentStatus> installmen
       return PaymentOptionStatus.PARTIALLY_PAID;
     } else if (isUnpayable(installmentStatusList)) {
       return PaymentOptionStatus.UNPAYABLE;
+    } else if (isDraft(installmentStatusList)) {
+      return PaymentOptionStatus.DRAFT;
     } else if (isUnpaid(installmentStatusList)) {
       return PaymentOptionStatus.UNPAID;
     } else if (isPaid(installmentStatusList)) {
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImpl.java b/src/main/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImpl.java
index 6695f6588..44be66041 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImpl.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImpl.java
@@ -5,6 +5,7 @@
 import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
 import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
 import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentStatus;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
 import it.gov.pagopa.pu.debtpositions.service.AuthorizeOperatorOnDebtPositionTypeService;
 import it.gov.pagopa.pu.debtpositions.service.BaseDebtPositionOperationService;
 import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
@@ -51,6 +52,16 @@ public String cancelInstallment(DebtPositionDTO debtPositionDTO, List<Installmen
 
   @Override
   protected void applyOperation(DebtPositionDTO debtPositionDTO, List<InstallmentDTO> installments2operate, String accessToken, Organization org) {
+    installments2operate = installments2operate.stream()
+      .filter(installmentDTO -> !InstallmentStatus.CANCELLED.equals(installmentDTO.getStatus()))
+      .map(installmentDTO -> {
+        if (!InstallmentUtils.MODIFIABLE_STATUSES.contains(installmentDTO.getStatus())) {
+          throw new ConflictErrorException("The installment with id " + installmentDTO.getInstallmentId() + " cannot be cancelled because is not in allowed status: " + installmentDTO.getStatus());
+        }
+        return installmentDTO;
+      })
+      .toList();
+
     Set<Long> installmentIds = installments2operate.stream().map(InstallmentDTO::getInstallmentId).collect(Collectors.toSet());
     log.debug("Updating status cancelled for installments with ids {}", installmentIds);
 
diff --git a/src/main/java/it/gov/pagopa/pu/debtpositions/util/InstallmentUtils.java b/src/main/java/it/gov/pagopa/pu/debtpositions/util/InstallmentUtils.java
index d38e087c9..08f2eba8e 100644
--- a/src/main/java/it/gov/pagopa/pu/debtpositions/util/InstallmentUtils.java
+++ b/src/main/java/it/gov/pagopa/pu/debtpositions/util/InstallmentUtils.java
@@ -38,6 +38,10 @@ private InstallmentUtils() {
     DebtPositionStatus.EXPIRED,
     DebtPositionStatus.PARTIALLY_PAID);
 
+  public static final Set<DebtPositionStatus> DELETABLE_DP_STATUSES = Set.of(
+    DebtPositionStatus.UNPAID,
+    DebtPositionStatus.EXPIRED);
+
   public static final Set<InstallmentStatus> MODIFIABLE_STATUSES = Set.of(
     InstallmentStatus.DRAFT,
     InstallmentStatus.UNPAID,
diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/controller/DebtPositionControllerTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/controller/DebtPositionControllerTest.java
index 80c33b9ae..7ee592953 100644
--- a/src/test/java/it/gov/pagopa/pu/debtpositions/controller/DebtPositionControllerTest.java
+++ b/src/test/java/it/gov/pagopa/pu/debtpositions/controller/DebtPositionControllerTest.java
@@ -7,6 +7,7 @@
 import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
 import it.gov.pagopa.pu.debtpositions.service.InstallmentService;
 import it.gov.pagopa.pu.debtpositions.service.create.debtposition.DebtPositionCreationService;
+import it.gov.pagopa.pu.debtpositions.service.delete.DebtPositionDeletionService;
 import it.gov.pagopa.pu.debtpositions.service.installmentsync.InstallmentSynchronizeService;
 import it.gov.pagopa.pu.debtpositions.service.statusalign.DebtPositionHierarchyStatusAlignerService;
 import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionManageInstallmentsService;
@@ -69,6 +70,9 @@ class DebtPositionControllerTest {
   @MockitoBean
   private DebtPositionManageInstallmentsService debtPositionManageInstallmentsService;
 
+  @MockitoBean
+  private DebtPositionDeletionService debtPositionDeletionService;
+
   private static final LocalDate DATE = LocalDate.of(2099, 1, 1);
   private static final OffsetDateTime DATETIME = OffsetDateTime.of(DATE, LocalTime.MIDNIGHT, ZoneOffset.UTC);
 
@@ -289,4 +293,18 @@ void whenUpdateInstallmentNotificationFeeThenOk()
       .andExpect(status().isOk())
       .andReturn();
   }
+
+  @Test
+  void whenDeleteDebtPositionThenOk() throws Exception {
+    Long debtPositionId = 1L;
+
+    Mockito.when(debtPositionDeletionService.deleteDebtPosition(debtPositionId, accessToken, userId)).thenReturn("workflowId");
+
+    mockMvc.perform(
+        delete("/debt-positions/" + debtPositionId)
+          .contentType(MediaType.APPLICATION_JSON_VALUE))
+      .andExpect(status().isNoContent())
+      .andExpect(header().string("x-workflow-id", "workflowId"))
+      .andReturn();
+  }
 }
diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepositoryImplTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepositoryImplTest.java
index 79e03acfe..74e43b7ed 100644
--- a/src/test/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepositoryImplTest.java
+++ b/src/test/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepositoryImplTest.java
@@ -27,6 +27,9 @@
 import java.util.List;
 import java.util.Optional;
 
+import static it.gov.pagopa.pu.debtpositions.util.faker.InstallmentFaker.*;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
 @ExtendWith(MockitoExtension.class)
 class InstallmentPIIRepositoryImplTest {
 
@@ -223,4 +226,16 @@ void givenValidOrganizationAndNavWhenGetByOrganizationIdAndNavThenOk(String debt
     installmentDTOList.forEach(installmentNoPII -> Mockito.verify(mapperMock, Mockito.times(1)).map(installmentNoPII));
   }
 
+  @Test
+  void givenInstallmentValidWhenDeleteThenOk(){
+    InstallmentNoPII noPII = buildInstallmentNoPII();
+
+    Mockito.doNothing().when(personalDataServiceMock).delete(123L);
+    Mockito.doNothing().when(installmentNoPIIRepository).delete(noPII);
+
+    assertDoesNotThrow(() -> installmentPIIRepository.delete(noPII));
+
+    Mockito.verify(personalDataServiceMock, Mockito.times(1)).delete(123L);
+    Mockito.verify(installmentNoPIIRepository, Mockito.times(1)).delete(noPII);
+  }
 }
diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionDeleteServiceTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionDeleteServiceTest.java
new file mode 100644
index 000000000..d10f12e0c
--- /dev/null
+++ b/src/test/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionDeleteServiceTest.java
@@ -0,0 +1,64 @@
+package it.gov.pagopa.pu.debtpositions.service;
+
+import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
+import it.gov.pagopa.pu.debtpositions.repository.DebtPositionRepository;
+import it.gov.pagopa.pu.debtpositions.repository.InstallmentPIIRepository;
+import it.gov.pagopa.pu.debtpositions.repository.PaymentOptionRepository;
+import it.gov.pagopa.pu.debtpositions.repository.TransferRepository;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static it.gov.pagopa.pu.debtpositions.util.faker.DebtPositionFaker.buildDebtPosition;
+
+@ExtendWith(MockitoExtension.class)
+class DebtPositionDeleteServiceTest {
+
+  @Mock
+  private DebtPositionRepository debtPositionRepositoryMock;
+  @Mock
+  private PaymentOptionRepository paymentOptionRepositoryMock;
+  @Mock
+  private InstallmentPIIRepository installmentPIIRepositoryMock;
+  @Mock
+  private TransferRepository transferRepositoryMock;
+
+  private DebtPositionDeleteService debtPositionDeleteService;
+
+  @BeforeEach
+  void setUp() {
+    debtPositionDeleteService = new DebtPositionDeleteService(
+      debtPositionRepositoryMock,
+      paymentOptionRepositoryMock,
+      installmentPIIRepositoryMock,
+      transferRepositoryMock
+    );
+  }
+
+  @AfterEach
+  void verifyNoMoreInteractions(){
+    Mockito.verifyNoMoreInteractions(
+      debtPositionRepositoryMock,
+      paymentOptionRepositoryMock,
+      installmentPIIRepositoryMock,
+      transferRepositoryMock);
+  }
+
+  @Test
+  void whenDeleteThenSuccess(){
+    DebtPosition debtPosition = buildDebtPosition();
+
+    Mockito.doNothing().when(transferRepositoryMock).delete(debtPosition.getPaymentOptions().getFirst().getInstallments().getFirst().getTransfers().getFirst());
+    Mockito.doNothing().when(installmentPIIRepositoryMock).delete(debtPosition.getPaymentOptions().getFirst().getInstallments().getFirst());
+    Mockito.doNothing().when(paymentOptionRepositoryMock).delete(debtPosition.getPaymentOptions().getFirst());
+    Mockito.doNothing().when(debtPositionRepositoryMock).delete(debtPosition);
+
+    Assertions.assertDoesNotThrow(() -> debtPositionDeleteService.delete(debtPosition));
+  }
+
+}
diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionServiceImplTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionServiceImplTest.java
index 02bb9e0bf..444f243f5 100644
--- a/src/test/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionServiceImplTest.java
+++ b/src/test/java/it/gov/pagopa/pu/debtpositions/service/DebtPositionServiceImplTest.java
@@ -35,6 +35,8 @@ class DebtPositionServiceImplTest {
   private DebtPositionSaveService debtPositionSaveServiceMock;
   @Mock
   private DebtPositionMapper debtPositionMapperMock;
+  @Mock
+  private DebtPositionDeleteService debtPositionDeleteServiceMock;
 
   private DebtPositionServiceImpl debtPositionService;
 
@@ -45,7 +47,8 @@ void setUp() {
     debtPositionService = new DebtPositionServiceImpl(
       debtPositionRepositoryMock,
       debtPositionSaveServiceMock,
-      debtPositionMapperMock
+      debtPositionMapperMock,
+      debtPositionDeleteServiceMock
     );
   }
 
@@ -54,7 +57,8 @@ void verifyNoMoreInteractions(){
     Mockito.verifyNoMoreInteractions(
       debtPositionRepositoryMock,
       debtPositionSaveServiceMock,
-      debtPositionMapperMock);
+      debtPositionMapperMock,
+      debtPositionDeleteServiceMock);
   }
 
   @Test
@@ -128,5 +132,29 @@ void givenPagedDebtPositionWhenGetPagedDebtPositionsThenSuccess() {
 
     assertEquals(result, expectedPagedDebtPositions);
   }
+
+  @Test
+  void givenDebtPositionWhenGetDebtPositionNoPIIThenSuccess(){
+    Long debtPositionId = 1L;
+    DebtPosition debtPosition = podamFactory.manufacturePojo(DebtPosition.class);
+
+    Mockito.when(debtPositionRepositoryMock.findOneWithAllDataByDebtPositionId(debtPositionId)).thenReturn(debtPosition);
+
+    DebtPosition result = debtPositionService.getDebtPositionNoPII(debtPositionId);
+
+    Assertions.assertNotNull(result);
+    Assertions.assertSame(debtPosition, result);
+    Mockito.verifyNoMoreInteractions(debtPositionRepositoryMock);
+  }
+
+  @Test
+  void givenDebtPositionWhenDeleteThenSuccess(){
+    DebtPosition debtPosition = podamFactory.manufacturePojo(DebtPosition.class);
+
+    Mockito.doNothing().when(debtPositionDeleteServiceMock).delete(debtPosition);
+
+    Assertions.assertDoesNotThrow(() -> debtPositionService.delete(debtPosition));
+    Mockito.verifyNoMoreInteractions(debtPositionDeleteServiceMock);
+  }
 }
 
diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImplTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImplTest.java
new file mode 100644
index 000000000..8cdba4962
--- /dev/null
+++ b/src/test/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImplTest.java
@@ -0,0 +1,149 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.connector.organization.service.OrganizationService;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionStatus;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.exception.custom.InvalidValueException;
+import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
+import it.gov.pagopa.pu.debtpositions.service.AuthorizeOperatorOnDebtPositionTypeService;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.organization.dto.generated.Organization;
+import it.gov.pagopa.pu.organization.dto.generated.OrganizationStatus;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.List;
+import java.util.Optional;
+
+import static it.gov.pagopa.pu.debtpositions.util.faker.DebtPositionFaker.buildDebtPosition;
+import static it.gov.pagopa.pu.debtpositions.util.faker.DebtPositionFaker.buildDebtPositionDTO;
+import static it.gov.pagopa.pu.debtpositions.util.faker.DebtPositionTypeOrgFaker.buildDebtPositionTypeOrg;
+import static it.gov.pagopa.pu.debtpositions.util.faker.OrganizationFaker.buildOrganization;
+import static org.junit.jupiter.api.Assertions.*;
+
+@ExtendWith(MockitoExtension.class)
+class DebtPositionDeletionServiceImplTest {
+
+  @Mock
+  private DebtPositionService debtPositionServiceMock;
+  @Mock
+  private OrganizationService organizationServiceMock;
+  @Mock
+  private AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeServiceMock;
+  @Mock
+  private DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentServiceMock;
+
+  private DebtPositionDeletionService debtPositionDeletionService;
+
+  private static final String OPERATOR_EXTERNAL_ID = "operatorExternalId";
+  private static final String ACCESS_TOKEN = "accessToken";
+  private static final String WORKFLOW_ID = "workflowId";
+
+  @BeforeEach
+  void setUp() {
+    debtPositionDeletionService = new DebtPositionDeletionServiceImpl(debtPositionServiceMock,
+      organizationServiceMock, authorizeOperatorOnDebtPositionTypeServiceMock,
+      debtPositionCancelInstallmentServiceMock);
+  }
+
+  @Test
+  void givenDraftDebtPositionWhenDeleteThenNoWorkflow() {
+    Long debtPositionId = 1L;
+    Organization organization = buildOrganization();
+    DebtPosition debtPosition = buildDebtPosition();
+    debtPosition.setStatus(DebtPositionStatus.DRAFT);
+
+    Mockito.when(debtPositionServiceMock.getDebtPositionNoPII(debtPositionId)).thenReturn(debtPosition);
+    Mockito.when(organizationServiceMock.getOrganizationById(debtPosition.getOrganizationId(), ACCESS_TOKEN)).thenReturn(Optional.ofNullable(organization));
+    Mockito.when(authorizeOperatorOnDebtPositionTypeServiceMock.authorize(organization.getIpaCode(), debtPosition.getDebtPositionTypeOrgId(), OPERATOR_EXTERNAL_ID))
+      .thenReturn(buildDebtPositionTypeOrg());
+    Mockito.doNothing().when(debtPositionServiceMock).delete(debtPosition);
+
+    String result = debtPositionDeletionService.deleteDebtPosition(debtPositionId, ACCESS_TOKEN, OPERATOR_EXTERNAL_ID);
+
+    assertNull(result);
+    Mockito.verify(debtPositionCancelInstallmentServiceMock, Mockito.times(0))
+      .cancelInstallment(Mockito.any(), Mockito.anyList(), Mockito.any(), Mockito.anyString(), Mockito.anyString());
+  }
+
+  @Test
+  void givenDraftDebtPositionWithOrgInactiveWhenDeleteThenThrowException() {
+    Long debtPositionId = 1L;
+    Organization organization = buildOrganization();
+    organization.setStatus(OrganizationStatus.DRAFT);
+    DebtPosition debtPosition = buildDebtPosition();
+    debtPosition.setStatus(DebtPositionStatus.DRAFT);
+
+    Mockito.when(debtPositionServiceMock.getDebtPositionNoPII(debtPositionId)).thenReturn(debtPosition);
+    Mockito.when(organizationServiceMock.getOrganizationById(debtPosition.getOrganizationId(), ACCESS_TOKEN)).thenReturn(Optional.of(organization));
+
+    InvalidValueException exception = assertThrows(InvalidValueException.class,
+      () -> debtPositionDeletionService.deleteDebtPosition(debtPositionId, ACCESS_TOKEN, OPERATOR_EXTERNAL_ID));
+
+    assertEquals("Provided organization is not ACTIVE", exception.getMessage());
+
+  }
+
+  @Test
+  void givenDebtPositionWithInstallmentNotifiedWhenDeleteThenThrowException() {
+    Long debtPositionId = 1L;
+    DebtPosition debtPosition = buildDebtPosition();
+
+    Mockito.when(debtPositionServiceMock.getDebtPositionNoPII(debtPositionId)).thenReturn(debtPosition);
+
+    ConflictErrorException exception = assertThrows(ConflictErrorException.class,
+      () -> debtPositionDeletionService.deleteDebtPosition(debtPositionId, ACCESS_TOKEN, OPERATOR_EXTERNAL_ID));
+
+    assertEquals("The debt position with id 1 cannot be deleted because it is been notified", exception.getMessage());
+
+    Mockito.verify(debtPositionCancelInstallmentServiceMock, Mockito.times(0))
+      .cancelInstallment(Mockito.any(), Mockito.anyList(), Mockito.any(), Mockito.anyString(), Mockito.anyString());
+  }
+
+  @Test
+  void givenDebtPositionInPaidStatusWhenDeleteThenThrowException() {
+    Long debtPositionId = 1L;
+    DebtPosition debtPosition = buildDebtPosition();
+    debtPosition.getPaymentOptions().getFirst().getInstallments().getFirst().setIun(null);
+    debtPosition.setStatus(DebtPositionStatus.PAID);
+
+    Mockito.when(debtPositionServiceMock.getDebtPositionNoPII(debtPositionId)).thenReturn(debtPosition);
+
+    ConflictErrorException exception = assertThrows(ConflictErrorException.class,
+      () -> debtPositionDeletionService.deleteDebtPosition(debtPositionId, ACCESS_TOKEN, OPERATOR_EXTERNAL_ID));
+
+    assertEquals("The debt position with id 1 cannot be deleted because is not in allowed status: PAID", exception.getMessage());
+
+    Mockito.verify(debtPositionCancelInstallmentServiceMock, Mockito.times(0))
+      .cancelInstallment(Mockito.any(), Mockito.anyList(), Mockito.any(), Mockito.anyString(), Mockito.anyString());
+  }
+
+  @Test
+  void givenDebtPositionUnpaidWhenDeleteThenSuccess() {
+    Long debtPositionId = 1L;
+    WfExecutionParameters wfExecutionParameters = WfExecutionParameters.builder().massive(false).partialChange(false).build();
+    DebtPosition debtPosition = buildDebtPosition();
+    debtPosition.setStatus(DebtPositionStatus.UNPAID);
+    debtPosition.getPaymentOptions().getFirst().getInstallments().getFirst().setIun(null);
+    DebtPositionDTO debtPositionDTO = buildDebtPositionDTO();
+
+    Mockito.when(debtPositionServiceMock.getDebtPositionNoPII(debtPositionId)).thenReturn(debtPosition);
+    Mockito.when(debtPositionServiceMock.mapDebtPosition(debtPosition)).thenReturn(debtPositionDTO);
+    Mockito.when(debtPositionCancelInstallmentServiceMock.cancelInstallment(debtPositionDTO,
+        List.of(debtPositionDTO.getPaymentOptions().getFirst().getInstallments().getFirst()), wfExecutionParameters, ACCESS_TOKEN, OPERATOR_EXTERNAL_ID))
+      .thenReturn(WORKFLOW_ID);
+
+    String result = debtPositionDeletionService.deleteDebtPosition(debtPositionId, ACCESS_TOKEN, OPERATOR_EXTERNAL_ID);
+
+    assertEquals(WORKFLOW_ID, result);
+
+  }
+
+}
diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/service/statusalign/debtposition/DebtPositionStatusCheckerTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/service/statusalign/debtposition/DebtPositionStatusCheckerTest.java
index efe1f2437..432faf4d4 100644
--- a/src/test/java/it/gov/pagopa/pu/debtpositions/service/statusalign/debtposition/DebtPositionStatusCheckerTest.java
+++ b/src/test/java/it/gov/pagopa/pu/debtpositions/service/statusalign/debtposition/DebtPositionStatusCheckerTest.java
@@ -63,6 +63,16 @@ void testCalculateNewStatus_Unpaid() {
     assertEquals(DebtPositionStatus.UNPAID, result);
   }
 
+  /**
+   * Test if the status is DRAFT when all paymentOptions are DRAFT.
+   */
+  @Test
+  void testCalculateNewStatus_Draft() {
+    List<PaymentOptionStatus> paymentOptionStatusList = List.of(PaymentOptionStatus.DRAFT, PaymentOptionStatus.DRAFT);
+    DebtPositionStatus result = checker.calculateNewStatus(paymentOptionStatusList);
+    assertEquals(DebtPositionStatus.DRAFT, result);
+  }
+
   /**
    * Test if the status is UNPAID when all paymentOptions are CANCELLED, with at least one UNPAID.
    */
diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/service/statusalign/paymentoption/PaymentOptionStatusCheckerTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/service/statusalign/paymentoption/PaymentOptionStatusCheckerTest.java
index 65c1b3cc9..3fc558946 100644
--- a/src/test/java/it/gov/pagopa/pu/debtpositions/service/statusalign/paymentoption/PaymentOptionStatusCheckerTest.java
+++ b/src/test/java/it/gov/pagopa/pu/debtpositions/service/statusalign/paymentoption/PaymentOptionStatusCheckerTest.java
@@ -80,6 +80,16 @@ void testCalculateNewStatus_Unpaid() {
     assertEquals(PaymentOptionStatus.UNPAID, result);
   }
 
+  /**
+   * Test if the status is DRAFT when all installments are DRAFT.
+   */
+  @Test
+  void testCalculateNewStatus_Draft() {
+    List<InstallmentStatus> installmentStatusList = List.of(InstallmentStatus.DRAFT, InstallmentStatus.DRAFT);
+    PaymentOptionStatus result = checker.calculateNewStatus(installmentStatusList);
+    assertEquals(PaymentOptionStatus.DRAFT, result);
+  }
+
   /**
    * Test if the status is UNPAID when all installments are CANCELLED, with at least one UNPAID.
    */
diff --git a/src/test/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImplTest.java b/src/test/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImplTest.java
index 64d636d6d..212086e3f 100644
--- a/src/test/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImplTest.java
+++ b/src/test/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImplTest.java
@@ -2,10 +2,8 @@
 
 import it.gov.pagopa.pu.debtpositions.connector.organization.service.OrganizationService;
 import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
-import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
-import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionStatus;
-import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentStatus;
-import it.gov.pagopa.pu.debtpositions.dto.generated.PaymentOptionStatus;
+import it.gov.pagopa.pu.debtpositions.dto.generated.*;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
 import it.gov.pagopa.pu.debtpositions.model.DebtPositionTypeOrg;
 import it.gov.pagopa.pu.debtpositions.model.InstallmentSyncStatus;
 import it.gov.pagopa.pu.debtpositions.service.AuthorizeOperatorOnDebtPositionTypeService;
@@ -31,6 +29,7 @@
 import static it.gov.pagopa.pu.debtpositions.util.faker.InstallmentFaker.buildInstallmentDTO;
 import static it.gov.pagopa.pu.debtpositions.util.faker.OrganizationFaker.buildOrganization;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 @ExtendWith(MockitoExtension.class)
 class DebtPositionCancelInstallmentServiceImplTest {
@@ -88,4 +87,22 @@ void testCancelInstallmentThenOK(){
     Mockito.verify(debtPositionServiceMock).saveDebtPosition(debtPositionDTO);
     Mockito.verify(debtPositionHierarchyStatusAlignerServiceMock).alignHierarchyStatus(debtPositionDTO);
   }
+
+  @Test
+  void givenInstallmentInStatusPaidWhenCancelThenException(){
+    String accessToken = "ACCESSTOKEN";
+    WfExecutionParameters wfExecutionParameters = new WfExecutionParameters();
+    String operatorExternalId = "OPERATOREXTERNALID";
+
+    Organization organization = buildOrganization();
+    DebtPositionDTO debtPositionDTO = buildDebtPositionDTO();
+    DebtPositionTypeOrg debtPositionTypeOrg = buildDebtPositionTypeOrg();
+    List<InstallmentDTO> installments = List.of(buildInstallmentDTO().status(InstallmentStatus.PAID));
+
+    Mockito.when(organizationServiceMock.getOrganizationById(debtPositionDTO.getOrganizationId(), accessToken)).thenReturn(Optional.of(organization));
+    Mockito.when(authorizeOperatorOnDebtPositionTypeServiceMock.authorize(organization.getIpaCode(), 2L, operatorExternalId)).thenReturn(debtPositionTypeOrg);
+
+    ConflictErrorException exception = assertThrows(ConflictErrorException.class, () -> debtPositionCancelInstallmentService.cancelInstallment(debtPositionDTO, installments, wfExecutionParameters, accessToken, operatorExternalId));
+    assertEquals("The installment with id 100 cannot be cancelled because is not in allowed status: PAID", exception.getMessage());
+  }
 }


Reviews:
user: login: antonioT90
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-23T14:57:13Z
user: login: antonioT90
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T08:39:41Z
user: login: antonioT90
state: CHANGES_REQUESTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T10:14:54Z
user: login: antonioT90
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-24T10:49:32Z

Review comments:
diff_hunk: @@ -789,6 +789,46 @@ paths:
             application/json:
               schema:
                 $ref: '#/components/schemas/DebtPositionErrorDTO'
+  /debt-positions/{debtPositionId}/delete:
path: openapi/p4pa-debt-position.openapi.yaml
user: login: antonioT90
body: is redundant to have the action on the path, we have already the HTTP method to express the delete operation
```suggestion
  /debt-positions/{debtPositionId}:
```
created_at: 2025-04-23T14:33:07Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,101 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.dto.Installment;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionStatus;
+import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.PaymentOptionDTO;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.mapper.InstallmentMapper;
+import it.gov.pagopa.pu.debtpositions.repository.*;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.debtpositions.util.InstallmentUtils;
+import jakarta.transaction.Transactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DebtPositionDeletionServiceImpl implements DebtPositionDeletionService {
+
+  private final DebtPositionService debtPositionService;
+  private final DebtPositionRepository debtPositionRepository;
+  private final PaymentOptionRepository paymentOptionRepository;
+  private final InstallmentPIIRepository installmentPIIRepository;
+  private final TransferRepository transferRepository;
+  private final InstallmentMapper installmentMapper;
+  private final DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService;
+
+  public DebtPositionDeletionServiceImpl(DebtPositionService debtPositionService, DebtPositionRepository debtPositionRepository, PaymentOptionRepository paymentOptionRepository, InstallmentPIIRepository installmentPIIRepository, TransferRepository transferRepository, InstallmentMapper installmentMapper, DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService) {
+    this.debtPositionService = debtPositionService;
+    this.debtPositionRepository = debtPositionRepository;
+    this.paymentOptionRepository = paymentOptionRepository;
+    this.installmentPIIRepository = installmentPIIRepository;
+    this.transferRepository = transferRepository;
+    this.installmentMapper = installmentMapper;
+    this.debtPositionCancelInstallmentService = debtPositionCancelInstallmentService;
+  }
+
+  @Override
+  @Transactional
+  public String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId) {
+    log.info("Cancelling debt position having id {}", debtPositionId);
+
+    DebtPositionDTO debtPositionDTO = debtPositionService.getDebtPosition(debtPositionId);
path: src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
user: login: antonioT90
body: let's not fetch PII if not required, you could expose a getDebtPositionNoPII method on DebtPositionService where to call just the method:
debtPositionRepository.findOneWithAllDataByDebtPositionId(debtPositionId)
then you could modify the actual getDebtPosition method in order perform the fetch using the new method instead of invoking again the repository.

If the debtPosition is not DRAFT, you could resolve the PII just calling the method
it.gov.pagopa.pu.debtpositions.service.DebtPositionServiceImpl#mapDebtPosition

created_at: 2025-04-23T14:48:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,101 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.dto.Installment;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionStatus;
+import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.PaymentOptionDTO;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.mapper.InstallmentMapper;
+import it.gov.pagopa.pu.debtpositions.repository.*;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.debtpositions.util.InstallmentUtils;
+import jakarta.transaction.Transactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DebtPositionDeletionServiceImpl implements DebtPositionDeletionService {
+
+  private final DebtPositionService debtPositionService;
+  private final DebtPositionRepository debtPositionRepository;
+  private final PaymentOptionRepository paymentOptionRepository;
+  private final InstallmentPIIRepository installmentPIIRepository;
+  private final TransferRepository transferRepository;
+  private final InstallmentMapper installmentMapper;
+  private final DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService;
+
+  public DebtPositionDeletionServiceImpl(DebtPositionService debtPositionService, DebtPositionRepository debtPositionRepository, PaymentOptionRepository paymentOptionRepository, InstallmentPIIRepository installmentPIIRepository, TransferRepository transferRepository, InstallmentMapper installmentMapper, DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService) {
+    this.debtPositionService = debtPositionService;
+    this.debtPositionRepository = debtPositionRepository;
+    this.paymentOptionRepository = paymentOptionRepository;
+    this.installmentPIIRepository = installmentPIIRepository;
+    this.transferRepository = transferRepository;
+    this.installmentMapper = installmentMapper;
+    this.debtPositionCancelInstallmentService = debtPositionCancelInstallmentService;
+  }
+
+  @Override
+  @Transactional
+  public String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId) {
+    log.info("Cancelling debt position having id {}", debtPositionId);
+
+    DebtPositionDTO debtPositionDTO = debtPositionService.getDebtPosition(debtPositionId);
+
+    if (DebtPositionStatus.DRAFT.equals(debtPositionDTO.getStatus())) {
+      deleteEntireDebtPosition(debtPositionDTO);
path: src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
user: login: antonioT90
body: Here you should as first check if the operator is authorize to act on the debtPosition as first.
Then, the delete would operate on NoPII model: this would simplify the PII delete, because you already know its id!

ps: move the DRAFT handling on a separate method
created_at: 2025-04-23T14:50:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,101 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.dto.Installment;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionStatus;
+import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.PaymentOptionDTO;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.mapper.InstallmentMapper;
+import it.gov.pagopa.pu.debtpositions.repository.*;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.debtpositions.util.InstallmentUtils;
+import jakarta.transaction.Transactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DebtPositionDeletionServiceImpl implements DebtPositionDeletionService {
+
+  private final DebtPositionService debtPositionService;
+  private final DebtPositionRepository debtPositionRepository;
+  private final PaymentOptionRepository paymentOptionRepository;
+  private final InstallmentPIIRepository installmentPIIRepository;
+  private final TransferRepository transferRepository;
+  private final InstallmentMapper installmentMapper;
+  private final DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService;
+
+  public DebtPositionDeletionServiceImpl(DebtPositionService debtPositionService, DebtPositionRepository debtPositionRepository, PaymentOptionRepository paymentOptionRepository, InstallmentPIIRepository installmentPIIRepository, TransferRepository transferRepository, InstallmentMapper installmentMapper, DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService) {
+    this.debtPositionService = debtPositionService;
+    this.debtPositionRepository = debtPositionRepository;
+    this.paymentOptionRepository = paymentOptionRepository;
+    this.installmentPIIRepository = installmentPIIRepository;
+    this.transferRepository = transferRepository;
+    this.installmentMapper = installmentMapper;
+    this.debtPositionCancelInstallmentService = debtPositionCancelInstallmentService;
+  }
+
+  @Override
+  @Transactional
+  public String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId) {
+    log.info("Cancelling debt position having id {}", debtPositionId);
+
+    DebtPositionDTO debtPositionDTO = debtPositionService.getDebtPosition(debtPositionId);
+
+    if (DebtPositionStatus.DRAFT.equals(debtPositionDTO.getStatus())) {
+      deleteEntireDebtPosition(debtPositionDTO);
+      log.info("Permanently deleted debt position with id {} having status DRAFT", debtPositionDTO.getDebtPositionId());
+      return null;
+    }
+
+    if(isIunPresent(debtPositionDTO)) {
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because it is been notified");
+    }
+
+    if(!InstallmentUtils.DELETABLE_DP_STATUSES.contains(debtPositionDTO.getStatus())){
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because is not in allowed status: " + debtPositionDTO.getStatus());
+    }
+
+    List<InstallmentDTO> installment2operate = debtPositionDTO.getPaymentOptions().stream()
path: src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
user: login: antonioT90
body: before this line is when you should resolve the PII using the suggested method
created_at: 2025-04-23T14:51:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,101 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.dto.Installment;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionStatus;
+import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.PaymentOptionDTO;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.mapper.InstallmentMapper;
+import it.gov.pagopa.pu.debtpositions.repository.*;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.debtpositions.util.InstallmentUtils;
+import jakarta.transaction.Transactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DebtPositionDeletionServiceImpl implements DebtPositionDeletionService {
+
+  private final DebtPositionService debtPositionService;
+  private final DebtPositionRepository debtPositionRepository;
+  private final PaymentOptionRepository paymentOptionRepository;
+  private final InstallmentPIIRepository installmentPIIRepository;
+  private final TransferRepository transferRepository;
+  private final InstallmentMapper installmentMapper;
+  private final DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService;
+
+  public DebtPositionDeletionServiceImpl(DebtPositionService debtPositionService, DebtPositionRepository debtPositionRepository, PaymentOptionRepository paymentOptionRepository, InstallmentPIIRepository installmentPIIRepository, TransferRepository transferRepository, InstallmentMapper installmentMapper, DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService) {
+    this.debtPositionService = debtPositionService;
+    this.debtPositionRepository = debtPositionRepository;
+    this.paymentOptionRepository = paymentOptionRepository;
+    this.installmentPIIRepository = installmentPIIRepository;
+    this.transferRepository = transferRepository;
+    this.installmentMapper = installmentMapper;
+    this.debtPositionCancelInstallmentService = debtPositionCancelInstallmentService;
+  }
+
+  @Override
+  @Transactional
+  public String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId) {
+    log.info("Cancelling debt position having id {}", debtPositionId);
+
+    DebtPositionDTO debtPositionDTO = debtPositionService.getDebtPosition(debtPositionId);
+
+    if (DebtPositionStatus.DRAFT.equals(debtPositionDTO.getStatus())) {
+      deleteEntireDebtPosition(debtPositionDTO);
+      log.info("Permanently deleted debt position with id {} having status DRAFT", debtPositionDTO.getDebtPositionId());
+      return null;
+    }
+
+    if(isIunPresent(debtPositionDTO)) {
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because it is been notified");
+    }
+
+    if(!InstallmentUtils.DELETABLE_DP_STATUSES.contains(debtPositionDTO.getStatus())){
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because is not in allowed status: " + debtPositionDTO.getStatus());
+    }
+
+    List<InstallmentDTO> installment2operate = debtPositionDTO.getPaymentOptions().stream()
+      .map(PaymentOptionDTO::getInstallments).flatMap(Collection::stream).toList();
+
+    WfExecutionParameters wfExecutionParameters = WfExecutionParameters.builder()
+      .partialChange(false)
+      .massive(false)
+      .build();
+
+    return debtPositionCancelInstallmentService.cancelInstallment(debtPositionDTO, installment2operate, wfExecutionParameters, accessToken, operatorExternalUserId);
+  }
+
+
+  private void deleteEntireDebtPosition(DebtPositionDTO debtPositionDTO) {
path: src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
user: login: antonioT90
body: let's move this method in the DebtPositionService method (let's just call it `delete`).
This way this service could be unaware of the Repository objects
created_at: 2025-04-23T14:52:53Z
author_association: CONTRIBUTOR
diff_hunk: @@ -10,4 +10,6 @@ public interface InstallmentPIIRepository {
   Installment save(Installment installment);
 
   List<Installment> getByOrganizationIdAndNav(Long organizationId, String nav, List<DebtPositionOrigin> debtPositionOrigin);
+
+  void delete(Installment installment);
path: src/main/java/it/gov/pagopa/pu/debtpositions/repository/InstallmentPIIRepository.java
user: login: antonioT90
body: this method could now accept directly InstallmentNoPII
created_at: 2025-04-23T14:55:10Z
author_association: CONTRIBUTOR
diff_hunk: @@ -72,4 +72,16 @@ protected Pair<Long, Optional<P>> retrievePII(E noPii) {
     }
   }
 
+  public void delete(F fullDTO) {
+    Pair<E, P> p = piiMapper.map(fullDTO);
+
+    Pair<Long, Optional<P>> retrievedPII = retrievePII(p.getFirst());
+
+    if (retrievedPII != null) {
+      personalDataService.delete(retrievedPII.getFirst());
+    }
+
+    noPIIRepository.delete(p.getFirst());
+  }
path: src/main/java/it/gov/pagopa/pu/debtpositions/repository/BasePIIRepository.java
user: login: antonioT90
body: this now could handle directly the NoPII entity
```suggestion
  public void delete(e noPii) {
    personalDataService.delete(e.getPersonalDataId());
    noPIIRepository.delete(e);
  }
```
created_at: 2025-04-23T14:57:09Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,94 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.connector.organization.service.OrganizationService;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionStatus;
+import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.PaymentOptionDTO;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.exception.custom.InvalidValueException;
+import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
+import it.gov.pagopa.pu.debtpositions.service.AuthorizeOperatorOnDebtPositionTypeService;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.debtpositions.util.InstallmentUtils;
+import it.gov.pagopa.pu.organization.dto.generated.Organization;
+import it.gov.pagopa.pu.organization.dto.generated.OrganizationStatus;
+import jakarta.transaction.Transactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DebtPositionDeletionServiceImpl implements DebtPositionDeletionService {
+
+  private final DebtPositionService debtPositionService;
+  private final OrganizationService organizationService;
+  private final AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeService;
+  private final DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService;
+
+  public DebtPositionDeletionServiceImpl(DebtPositionService debtPositionService, OrganizationService organizationService, AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeService, DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService) {
+    this.debtPositionService = debtPositionService;
+    this.organizationService = organizationService;
+    this.authorizeOperatorOnDebtPositionTypeService = authorizeOperatorOnDebtPositionTypeService;
+    this.debtPositionCancelInstallmentService = debtPositionCancelInstallmentService;
+  }
+
+  @Override
+  @Transactional
+  public String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId) {
+    log.info("Cancelling debt position having id {}", debtPositionId);
+
+    DebtPosition debtPosition = debtPositionService.getDebtPositionNoPII(debtPositionId);
+
+    if (DebtPositionStatus.DRAFT.equals(debtPosition.getStatus())) {
+      manageDraftDebtPosition(debtPosition, accessToken, operatorExternalUserId);
+      return null;
+    }
+
+    if(isIunPresent(debtPosition)) {
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because it is been notified");
+    }
+
+    if(!InstallmentUtils.DELETABLE_DP_STATUSES.contains(debtPosition.getStatus())){
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because is not in allowed status: " + debtPosition.getStatus());
+    }
+
+    DebtPositionDTO debtPositionDTO = debtPositionService.mapDebtPosition(debtPosition);
+
+    List<InstallmentDTO> installment2operate = debtPositionDTO.getPaymentOptions().stream()
+      .map(PaymentOptionDTO::getInstallments).flatMap(Collection::stream).toList();
path: src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
user: login: antonioT90
body: should we skip CACELLED, INVALID, PAID and REPORTED status (new constant DELETABLE_DPI_STATUSES)?
created_at: 2025-04-24T08:37:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,94 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.connector.organization.service.OrganizationService;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.DebtPositionStatus;
+import it.gov.pagopa.pu.debtpositions.dto.generated.InstallmentDTO;
+import it.gov.pagopa.pu.debtpositions.dto.generated.PaymentOptionDTO;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.exception.custom.InvalidValueException;
+import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
+import it.gov.pagopa.pu.debtpositions.service.AuthorizeOperatorOnDebtPositionTypeService;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.debtpositions.util.InstallmentUtils;
+import it.gov.pagopa.pu.organization.dto.generated.Organization;
+import it.gov.pagopa.pu.organization.dto.generated.OrganizationStatus;
+import jakarta.transaction.Transactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DebtPositionDeletionServiceImpl implements DebtPositionDeletionService {
+
+  private final DebtPositionService debtPositionService;
+  private final OrganizationService organizationService;
+  private final AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeService;
+  private final DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService;
+
+  public DebtPositionDeletionServiceImpl(DebtPositionService debtPositionService, OrganizationService organizationService, AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeService, DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService) {
+    this.debtPositionService = debtPositionService;
+    this.organizationService = organizationService;
+    this.authorizeOperatorOnDebtPositionTypeService = authorizeOperatorOnDebtPositionTypeService;
+    this.debtPositionCancelInstallmentService = debtPositionCancelInstallmentService;
+  }
+
+  @Override
+  @Transactional
+  public String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId) {
+    log.info("Cancelling debt position having id {}", debtPositionId);
+
+    DebtPosition debtPosition = debtPositionService.getDebtPositionNoPII(debtPositionId);
+
+    if (DebtPositionStatus.DRAFT.equals(debtPosition.getStatus())) {
+      manageDraftDebtPosition(debtPosition, accessToken, operatorExternalUserId);
+      return null;
+    }
+
+    if(isIunPresent(debtPosition)) {
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because it is been notified");
+    }
+
+    if(!InstallmentUtils.DELETABLE_DP_STATUSES.contains(debtPosition.getStatus())){
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because is not in allowed status: " + debtPosition.getStatus());
+    }
+
+    DebtPositionDTO debtPositionDTO = debtPositionService.mapDebtPosition(debtPosition);
+
+    List<InstallmentDTO> installment2operate = debtPositionDTO.getPaymentOptions().stream()
+      .map(PaymentOptionDTO::getInstallments).flatMap(Collection::stream).toList();
path: src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
user: login: antonioT90
body: ps: actually there is not such check on it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl#applyOperation, should we validate the status also there and throw an exception if violated?
created_at: 2025-04-24T08:38:22Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,93 @@
+package it.gov.pagopa.pu.debtpositions.service.delete;
+
+import it.gov.pagopa.pu.debtpositions.connector.organization.service.OrganizationService;
+import it.gov.pagopa.pu.debtpositions.dto.WfExecutionParameters;
+import it.gov.pagopa.pu.debtpositions.dto.generated.*;
+import it.gov.pagopa.pu.debtpositions.exception.custom.ConflictErrorException;
+import it.gov.pagopa.pu.debtpositions.exception.custom.InvalidValueException;
+import it.gov.pagopa.pu.debtpositions.model.DebtPosition;
+import it.gov.pagopa.pu.debtpositions.service.AuthorizeOperatorOnDebtPositionTypeService;
+import it.gov.pagopa.pu.debtpositions.service.DebtPositionService;
+import it.gov.pagopa.pu.debtpositions.service.update.DebtPositionCancelInstallmentServiceImpl;
+import it.gov.pagopa.pu.debtpositions.util.InstallmentUtils;
+import it.gov.pagopa.pu.organization.dto.generated.Organization;
+import it.gov.pagopa.pu.organization.dto.generated.OrganizationStatus;
+import jakarta.transaction.Transactional;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.Collection;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DebtPositionDeletionServiceImpl implements DebtPositionDeletionService {
+
+  private final DebtPositionService debtPositionService;
+  private final OrganizationService organizationService;
+  private final AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeService;
+  private final DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService;
+
+  public DebtPositionDeletionServiceImpl(DebtPositionService debtPositionService, OrganizationService organizationService, AuthorizeOperatorOnDebtPositionTypeService authorizeOperatorOnDebtPositionTypeService, DebtPositionCancelInstallmentServiceImpl debtPositionCancelInstallmentService) {
+    this.debtPositionService = debtPositionService;
+    this.organizationService = organizationService;
+    this.authorizeOperatorOnDebtPositionTypeService = authorizeOperatorOnDebtPositionTypeService;
+    this.debtPositionCancelInstallmentService = debtPositionCancelInstallmentService;
+  }
+
+  @Override
+  @Transactional
+  public String deleteDebtPosition(Long debtPositionId, String accessToken, String operatorExternalUserId) {
+    log.info("Cancelling debt position having id {}", debtPositionId);
+
+    DebtPosition debtPosition = debtPositionService.getDebtPositionNoPII(debtPositionId);
+
+    if (DebtPositionStatus.DRAFT.equals(debtPosition.getStatus())) {
+      deleteDraftDebtPosition(debtPosition, accessToken, operatorExternalUserId);
+      return null;
+    }
+
+    if(isIunPresent(debtPosition)) {
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because it is been notified");
+    }
+
+    if(!InstallmentUtils.DELETABLE_DP_STATUSES.contains(debtPosition.getStatus())){
+      throw new ConflictErrorException("The debt position with id " + debtPositionId + " cannot be deleted because is not in allowed status: " + debtPosition.getStatus());
+    }
+
+    DebtPositionDTO debtPositionDTO = debtPositionService.mapDebtPosition(debtPosition);
+
+    List<InstallmentDTO> installment2operate = debtPositionDTO.getPaymentOptions().stream()
+      .map(PaymentOptionDTO::getInstallments).flatMap(Collection::stream)
+      .filter(installmentDTO -> !InstallmentStatus.CANCELLED.equals(installmentDTO.getStatus()))
path: src/main/java/it/gov/pagopa/pu/debtpositions/service/delete/DebtPositionDeletionServiceImpl.java
user: login: antonioT90
body: you should skip also INVALID
```suggestion
      .filter(installmentDTO -> InstallmentUtils.MODIFIABLE_STATUSES.contains(installmentDTO.getStatus()))
```
created_at: 2025-04-24T10:10:18Z
author_association: CONTRIBUTOR
diff_hunk: @@ -51,6 +52,14 @@ public String cancelInstallment(DebtPositionDTO debtPositionDTO, List<Installmen
 
   @Override
   protected void applyOperation(DebtPositionDTO debtPositionDTO, List<InstallmentDTO> installments2operate, String accessToken, Organization org) {
+    List<String> installmentsNonCancellable = installments2operate.stream()
+      .filter(installmentDTO -> !InstallmentUtils.MODIFIABLE_STATUSES.contains(installmentDTO.getStatus()))
path: src/main/java/it/gov/pagopa/pu/debtpositions/service/update/DebtPositionCancelInstallmentServiceImpl.java
user: login: antonioT90
body: just CANCELLED installment could be ignored, other statuses will be errors
```suggestion
      .filter(installmentDTO -> !InstallmentStatus.CANCELLED.equals(installmentDTO.getStatus()))
      .map(installmentDTO -> {
         if(!InstallmentUtils.MODIFIABLE_STATUSES.contains(installmentDTO.getStatus())) {
            throw new ConflictErrorException("The installment with id " + installmentDTO.getInstallmentId() + " cannot be cancelled because is not in allowed status: " + installmentDTO.getStatus());
         }
         return installmentDTO;
      })
```
created_at: 2025-04-24T10:14:47Z
author_association: CONTRIBUTOR

PR comments:
user: login: sonarqubecloud[bot]
created_at: 2025-04-24T10:46:14Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=pagopa_p4pa-debt-positions&pullRequest=199) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [1 New issue](https://sonarcloud.io/project/issues?id=pagopa_p4pa-debt-positions&pullRequest=199&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=pagopa_p4pa-debt-positions&pullRequest=199&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=pagopa_p4pa-debt-positions&pullRequest=199&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [99.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=pagopa_p4pa-debt-positions&pullRequest=199&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=pagopa_p4pa-debt-positions&pullRequest=199&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=pagopa_p4pa-debt-positions&pullRequest=199)


author_association: NONE