
#include <stdio.h>
#include <string.h>
#include "app.h"
#include "GenCard.h"

/*
 *  Convert a rarity into a filename trailer.
 */

char * rarity_to_trailer(char *expansion, char *rarity)
{
	char *s;

	if (expansion)
	{
		s = app_alloc(strlen(expansion) + 20 + 1);

		sprintf(s, "%s %s", expansion, "Common");
		if (strstr(rarity, s) != NULL) {
			app_free(s);
			return "_Common";
		}

		sprintf(s, "%s %s", expansion, "Uncommon");
		if (strstr(rarity, s) != NULL) {
			app_free(s);
			return "_Uncommon";
		}

		sprintf(s, "%s %s", expansion, "MythicRare");
		if (strstr(rarity, s) != NULL) {
			app_free(s);
			return "_MythicRare";
		}

		sprintf(s, "%s %s", expansion, "Rare");
		if (strstr(rarity, s) != NULL) {
			app_free(s);
			return "_Rare";
		}

		sprintf(s, "%s %s", expansion, "BasicLand");
		if (strstr(rarity, s) != NULL) {
			app_free(s);
			return "_Common";
		}
		
		sprintf(s, "%s %s", expansion, "Special");
		if (strstr(rarity, s) != NULL) {
			app_free(s);
			return "_Special";
		}
	}

	switch (rarity[0])
	{
		case 'M': return "_MythicRare";
		case 'R': return "_Rare";
		case 'U': return "_Uncommon";
		case 'C': return "_Common";
		case 'S': return "_Special";
		default:  break;
	}
	return NULL;
}

